]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/c/c-errors.c
Update copyright years.
[thirdparty/gcc.git] / gcc / c / c-errors.c
CommitLineData
b9161f44 1/* Various diagnostic subroutines for the GNU C language.
85ec4feb 2 Copyright (C) 2000-2018 Free Software Foundation, Inc.
b9161f44
GDR
3 Contributed by Gabriel Dos Reis <gdr@codesourcery.com>
4
1322177d 5This file is part of GCC.
b9161f44 6
1322177d
LB
7GCC is free software; you can redistribute it and/or modify it under
8the terms of the GNU General Public License as published by the Free
9dcd6f09 9Software Foundation; either version 3, or (at your option) any later
1322177d 10version.
b9161f44 11
1322177d
LB
12GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or
14FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15for more details.
b9161f44
GDR
16
17You should have received a copy of the GNU General Public License
9dcd6f09
NC
18along with GCC; see the file COPYING3. If not see
19<http://www.gnu.org/licenses/>. */
b9161f44
GDR
20
21#include "config.h"
22#include "system.h"
4977bab6
ZW
23#include "coretypes.h"
24#include "tm.h"
b9161f44 25#include "c-tree.h"
177cce46 26#include "opts.h"
b9161f44 27
35aff4fb
MP
28/* Issue an ISO C99 pedantic warning MSGID if -pedantic outside C11 mode,
29 otherwise issue warning MSGID if -Wc99-c11-compat is specified.
30 This function is supposed to be used for matters that are allowed in
31 ISO C11 but not supported in ISO C99, thus we explicitly don't pedwarn
32 when C11 is specified. */
b9161f44 33
35aff4fb 34bool
509c9d60 35pedwarn_c99 (location_t location, int opt, const char *gmsgid, ...)
b9161f44 36{
47b69537 37 diagnostic_info diagnostic;
e34d07f2 38 va_list ap;
35aff4fb 39 bool warned = false;
ebedc9a3 40 rich_location richloc (line_table, location);
c22cacf3 41
4b794eaf 42 va_start (ap, gmsgid);
35aff4fb
MP
43 /* If desired, issue the C99/C11 compat warning, which is more specific
44 than -pedantic. */
45 if (warn_c99_c11_compat > 0)
46 {
8a645150 47 diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc,
35aff4fb
MP
48 (pedantic && !flag_isoc11)
49 ? DK_PEDWARN : DK_WARNING);
50 diagnostic.option_index = OPT_Wc99_c11_compat;
56d35585 51 warned = diagnostic_report_diagnostic (global_dc, &diagnostic);
35aff4fb
MP
52 }
53 /* -Wno-c99-c11-compat suppresses even the pedwarns. */
54 else if (warn_c99_c11_compat == 0)
55 ;
56 /* For -pedantic outside C11, issue a pedwarn. */
57 else if (pedantic && !flag_isoc11)
58 {
8a645150 59 diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc, DK_PEDWARN);
35aff4fb 60 diagnostic.option_index = opt;
56d35585 61 warned = diagnostic_report_diagnostic (global_dc, &diagnostic);
35aff4fb 62 }
e34d07f2 63 va_end (ap);
35aff4fb 64 return warned;
b9161f44 65}
85617eba 66
f3bede71
MP
67/* Issue an ISO C90 pedantic warning MSGID if -pedantic outside C99 mode,
68 otherwise issue warning MSGID if -Wc90-c99-compat is specified, or if
69 a specific option such as -Wlong-long is specified.
70 This function is supposed to be used for matters that are allowed in
71 ISO C99 but not supported in ISO C90, thus we explicitly don't pedwarn
72 when C99 is specified. (There is no flag_c90.) */
85617eba 73
d6e83a8d 74bool
509c9d60 75pedwarn_c90 (location_t location, int opt, const char *gmsgid, ...)
85617eba
HPN
76{
77 diagnostic_info diagnostic;
78 va_list ap;
d6e83a8d 79 bool warned = false;
ebedc9a3 80 rich_location richloc (line_table, location);
85617eba 81
4b794eaf 82 va_start (ap, gmsgid);
177cce46
MP
83 /* Warnings such as -Wvla are the most specific ones. */
84 if (opt != OPT_Wpedantic)
f3bede71 85 {
177cce46
MP
86 int opt_var = *(int *) option_flag_var (opt, &global_options);
87 if (opt_var == 0)
88 goto out;
89 else if (opt_var > 0)
90 {
8a645150 91 diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc,
177cce46
MP
92 (pedantic && !flag_isoc99)
93 ? DK_PEDWARN : DK_WARNING);
94 diagnostic.option_index = opt;
56d35585 95 diagnostic_report_diagnostic (global_dc, &diagnostic);
d6e83a8d 96 warned = true;
177cce46
MP
97 goto out;
98 }
f3bede71 99 }
177cce46
MP
100 /* Maybe we want to issue the C90/C99 compat warning, which is more
101 specific than -pedantic. */
102 if (warn_c90_c99_compat > 0)
f3bede71 103 {
8a645150 104 diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc,
177cce46
MP
105 (pedantic && !flag_isoc99)
106 ? DK_PEDWARN : DK_WARNING);
107 diagnostic.option_index = OPT_Wc90_c99_compat;
56d35585 108 diagnostic_report_diagnostic (global_dc, &diagnostic);
f3bede71 109 }
177cce46
MP
110 /* -Wno-c90-c99-compat suppresses the pedwarns. */
111 else if (warn_c90_c99_compat == 0)
112 ;
113 /* For -pedantic outside C99, issue a pedwarn. */
114 else if (pedantic && !flag_isoc99)
f3bede71 115 {
8a645150 116 diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc, DK_PEDWARN);
177cce46 117 diagnostic.option_index = opt;
56d35585 118 diagnostic_report_diagnostic (global_dc, &diagnostic);
d6e83a8d 119 warned = true;
f3bede71 120 }
177cce46 121out:
85617eba 122 va_end (ap);
d6e83a8d 123 return warned;
85617eba 124}