1 /* Various diagnostic subroutines for the GNU C language.
2 Copyright (C) 2000-2024 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
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
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 #define INCLUDE_MEMORY
24 #include "coretypes.h"
29 /* Issue an ISO C23 pedantic warning MSGID if -pedantic outside C2Y mode,
30 otherwise issue warning MSGID if -Wc23-c2y-compat is specified.
31 This function is supposed to be used for matters that are allowed in
32 ISO C2Y but not supported in ISO C23, thus we explicitly don't pedwarn
33 when C2Y is specified. */
36 pedwarn_c23 (location_t location
,
37 diagnostic_option_id option_id
,
38 const char *gmsgid
, ...)
40 diagnostic_info diagnostic
;
43 rich_location
richloc (line_table
, location
);
45 va_start (ap
, gmsgid
);
46 /* If desired, issue the C23/C2Y compat warning, which is more specific
48 if (warn_c23_c2y_compat
> 0)
50 diagnostic_set_info (&diagnostic
, gmsgid
, &ap
, &richloc
,
51 (pedantic
&& !flag_isoc2y
)
52 ? DK_PEDWARN
: DK_WARNING
);
53 diagnostic
.option_id
= OPT_Wc23_c2y_compat
;
54 warned
= diagnostic_report_diagnostic (global_dc
, &diagnostic
);
56 /* -Wno-c23-c2y-compat suppresses even the pedwarns. */
57 else if (warn_c23_c2y_compat
== 0)
59 /* For -pedantic outside C2Y, issue a pedwarn. */
60 else if (pedantic
&& !flag_isoc2y
)
62 diagnostic_set_info (&diagnostic
, gmsgid
, &ap
, &richloc
, DK_PEDWARN
);
63 diagnostic
.option_id
= option_id
;
64 warned
= diagnostic_report_diagnostic (global_dc
, &diagnostic
);
70 /* Issue an ISO C11 pedantic warning MSGID if -pedantic outside C23 mode,
71 otherwise issue warning MSGID if -Wc11-c23-compat is specified.
72 This function is supposed to be used for matters that are allowed in
73 ISO C23 but not supported in ISO C11, thus we explicitly don't pedwarn
74 when C23 is specified. */
77 pedwarn_c11 (location_t location
,
78 diagnostic_option_id option_id
,
79 const char *gmsgid
, ...)
81 diagnostic_info diagnostic
;
84 rich_location
richloc (line_table
, location
);
86 va_start (ap
, gmsgid
);
87 /* If desired, issue the C11/C23 compat warning, which is more specific
89 if (warn_c11_c23_compat
> 0)
91 diagnostic_set_info (&diagnostic
, gmsgid
, &ap
, &richloc
,
92 (pedantic
&& !flag_isoc23
)
93 ? DK_PEDWARN
: DK_WARNING
);
94 diagnostic
.option_id
= OPT_Wc11_c23_compat
;
95 warned
= diagnostic_report_diagnostic (global_dc
, &diagnostic
);
97 /* -Wno-c11-c23-compat suppresses even the pedwarns. */
98 else if (warn_c11_c23_compat
== 0)
100 /* For -pedantic outside C23, issue a pedwarn. */
101 else if (pedantic
&& !flag_isoc23
)
103 diagnostic_set_info (&diagnostic
, gmsgid
, &ap
, &richloc
, DK_PEDWARN
);
104 diagnostic
.option_id
= option_id
;
105 warned
= diagnostic_report_diagnostic (global_dc
, &diagnostic
);
111 /* Issue an ISO C99 pedantic warning MSGID if -pedantic outside C11 mode,
112 otherwise issue warning MSGID if -Wc99-c11-compat is specified.
113 This function is supposed to be used for matters that are allowed in
114 ISO C11 but not supported in ISO C99, thus we explicitly don't pedwarn
115 when C11 is specified. */
118 pedwarn_c99 (location_t location
,
119 diagnostic_option_id option_id
,
120 const char *gmsgid
, ...)
122 diagnostic_info diagnostic
;
125 rich_location
richloc (line_table
, location
);
127 va_start (ap
, gmsgid
);
128 /* If desired, issue the C99/C11 compat warning, which is more specific
130 if (warn_c99_c11_compat
> 0)
132 diagnostic_set_info (&diagnostic
, gmsgid
, &ap
, &richloc
,
133 (pedantic
&& !flag_isoc11
)
134 ? DK_PEDWARN
: DK_WARNING
);
135 diagnostic
.option_id
= OPT_Wc99_c11_compat
;
136 warned
= diagnostic_report_diagnostic (global_dc
, &diagnostic
);
138 /* -Wno-c99-c11-compat suppresses even the pedwarns. */
139 else if (warn_c99_c11_compat
== 0)
141 /* For -pedantic outside C11, issue a pedwarn. */
142 else if (pedantic
&& !flag_isoc11
)
144 diagnostic_set_info (&diagnostic
, gmsgid
, &ap
, &richloc
, DK_PEDWARN
);
145 diagnostic
.option_id
= option_id
;
146 warned
= diagnostic_report_diagnostic (global_dc
, &diagnostic
);
152 /* Issue an ISO C90 pedantic warning MSGID if -pedantic outside C99 mode,
153 otherwise issue warning MSGID if -Wc90-c99-compat is specified, or if
154 a specific option such as -Wlong-long is specified.
155 This function is supposed to be used for matters that are allowed in
156 ISO C99 but not supported in ISO C90, thus we explicitly don't pedwarn
157 when C99 is specified. (There is no flag_c90.) */
160 pedwarn_c90 (location_t location
,
161 diagnostic_option_id option_id
,
162 const char *gmsgid
, ...)
164 diagnostic_info diagnostic
;
167 rich_location
richloc (line_table
, location
);
169 va_start (ap
, gmsgid
);
170 /* Warnings such as -Wvla are the most specific ones. */
171 if (option_id
.m_idx
!= OPT_Wpedantic
)
173 int opt_var
= *(int *) option_flag_var (option_id
.m_idx
, &global_options
);
176 else if (opt_var
> 0)
178 diagnostic_set_info (&diagnostic
, gmsgid
, &ap
, &richloc
,
179 (pedantic
&& !flag_isoc99
)
180 ? DK_PEDWARN
: DK_WARNING
);
181 diagnostic
.option_id
= option_id
;
182 diagnostic_report_diagnostic (global_dc
, &diagnostic
);
187 /* Maybe we want to issue the C90/C99 compat warning, which is more
188 specific than -pedantic. */
189 if (warn_c90_c99_compat
> 0)
191 diagnostic_set_info (&diagnostic
, gmsgid
, &ap
, &richloc
,
192 (pedantic
&& !flag_isoc99
)
193 ? DK_PEDWARN
: DK_WARNING
);
194 diagnostic
.option_id
= OPT_Wc90_c99_compat
;
195 diagnostic_report_diagnostic (global_dc
, &diagnostic
);
197 /* -Wno-c90-c99-compat suppresses the pedwarns. */
198 else if (warn_c90_c99_compat
== 0)
200 /* For -pedantic outside C99, issue a pedwarn. */
201 else if (pedantic
&& !flag_isoc99
)
203 diagnostic_set_info (&diagnostic
, gmsgid
, &ap
, &richloc
, DK_PEDWARN
);
204 diagnostic
.option_id
= option_id
;
205 diagnostic_report_diagnostic (global_dc
, &diagnostic
);