struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / cpp / gcc / c / c-errors.cc
bloba0a1e6d10a539f12ecd225da8f837486423ac8e3
1 /* Various diagnostic subroutines for the GNU C language.
2 Copyright (C) 2000-2022 Free Software Foundation, Inc.
3 Contributed by Gabriel Dos Reis <gdr@codesourcery.com>
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
10 version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "tm.h"
25 #include "c-tree.h"
26 #include "opts.h"
27 #include "diagnostic.h" // sdcpp
29 /* Issue an ISO C11 pedantic warning MSGID if -pedantic outside C2X mode,
30 otherwise issue warning MSGID if -Wc11-c2X-compat is specified.
31 This function is supposed to be used for matters that are allowed in
32 ISO C2X but not supported in ISO C11, thus we explicitly don't pedwarn
33 when C2X is specified. */
35 bool
36 pedwarn_c11 (location_t location, int opt, const char *gmsgid, ...)
38 diagnostic_info diagnostic;
39 va_list ap;
40 bool warned = false;
41 rich_location richloc (line_table, location);
43 va_start (ap, gmsgid);
44 /* If desired, issue the C11/C2X compat warning, which is more specific
45 than -pedantic. */
46 if (warn_c11_c2x_compat > 0)
48 diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc,
49 (pedantic && !flag_isoc23)
50 ? DK_PEDWARN : DK_WARNING);
51 diagnostic.option_index = OPT_Wc11_c2x_compat;
52 warned = diagnostic_report_diagnostic (global_dc, &diagnostic);
54 /* -Wno-c11-c2x-compat suppresses even the pedwarns. */
55 else if (warn_c11_c2x_compat == 0)
57 /* For -pedantic outside C2X, issue a pedwarn. */
58 else if (pedantic && !flag_isoc23)
60 diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc, DK_PEDWARN);
61 diagnostic.option_index = opt;
62 warned = diagnostic_report_diagnostic (global_dc, &diagnostic);
64 va_end (ap);
65 return warned;
68 /* Issue an ISO C99 pedantic warning MSGID if -pedantic outside C11 mode,
69 otherwise issue warning MSGID if -Wc99-c11-compat is specified.
70 This function is supposed to be used for matters that are allowed in
71 ISO C11 but not supported in ISO C99, thus we explicitly don't pedwarn
72 when C11 is specified. */
74 bool
75 pedwarn_c99 (location_t location, int opt, const char *gmsgid, ...)
77 diagnostic_info diagnostic;
78 va_list ap;
79 bool warned = false;
80 rich_location richloc (line_table, location);
82 va_start (ap, gmsgid);
83 /* If desired, issue the C99/C11 compat warning, which is more specific
84 than -pedantic. */
85 if (warn_c99_c11_compat > 0)
87 diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc,
88 (pedantic && !flag_isoc11)
89 ? DK_PEDWARN : DK_WARNING);
90 diagnostic.option_index = OPT_Wc99_c11_compat;
91 warned = diagnostic_report_diagnostic (global_dc, &diagnostic);
93 /* -Wno-c99-c11-compat suppresses even the pedwarns. */
94 else if (warn_c99_c11_compat == 0)
96 /* For -pedantic outside C11, issue a pedwarn. */
97 else if (pedantic && !flag_isoc11)
99 diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc, DK_PEDWARN);
100 diagnostic.option_index = opt;
101 warned = diagnostic_report_diagnostic (global_dc, &diagnostic);
103 va_end (ap);
104 return warned;
107 /* Issue an ISO C90 pedantic warning MSGID if -pedantic outside C99 mode,
108 otherwise issue warning MSGID if -Wc90-c99-compat is specified, or if
109 a specific option such as -Wlong-long is specified.
110 This function is supposed to be used for matters that are allowed in
111 ISO C99 but not supported in ISO C90, thus we explicitly don't pedwarn
112 when C99 is specified. (There is no flag_c90.) */
114 bool
115 pedwarn_c90 (location_t location, int opt, const char *gmsgid, ...)
117 diagnostic_info diagnostic;
118 va_list ap;
119 bool warned = false;
120 rich_location richloc (line_table, location);
122 va_start (ap, gmsgid);
123 /* Warnings such as -Wvla are the most specific ones. */
124 if (opt != OPT_Wpedantic)
126 int opt_var = *(int *) option_flag_var (opt, &global_options);
127 if (opt_var == 0)
128 goto out;
129 else if (opt_var > 0)
131 diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc,
132 (pedantic && !flag_isoc99)
133 ? DK_PEDWARN : DK_WARNING);
134 diagnostic.option_index = opt;
135 diagnostic_report_diagnostic (global_dc, &diagnostic);
136 warned = true;
137 goto out;
140 /* Maybe we want to issue the C90/C99 compat warning, which is more
141 specific than -pedantic. */
142 if (warn_c90_c99_compat > 0)
144 diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc,
145 (pedantic && !flag_isoc99)
146 ? DK_PEDWARN : DK_WARNING);
147 diagnostic.option_index = OPT_Wc90_c99_compat;
148 diagnostic_report_diagnostic (global_dc, &diagnostic);
150 /* -Wno-c90-c99-compat suppresses the pedwarns. */
151 else if (warn_c90_c99_compat == 0)
153 /* For -pedantic outside C99, issue a pedwarn. */
154 else if (pedantic && !flag_isoc99)
156 diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc, DK_PEDWARN);
157 diagnostic.option_index = opt;
158 diagnostic_report_diagnostic (global_dc, &diagnostic);
159 warned = true;
161 out:
162 va_end (ap);
163 return warned;