1 /* Various diagnostic subroutines for the GNU C language.
2 Copyright (C) 2000-2018 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/>. */
23 #include "coretypes.h"
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. */
35 pedwarn_c99 (location_t location
, int opt
, const char *gmsgid
, ...)
37 diagnostic_info diagnostic
;
40 rich_location
richloc (line_table
, location
);
42 va_start (ap
, gmsgid
);
43 /* If desired, issue the C99/C11 compat warning, which is more specific
45 if (warn_c99_c11_compat
> 0)
47 diagnostic_set_info (&diagnostic
, gmsgid
, &ap
, &richloc
,
48 (pedantic
&& !flag_isoc11
)
49 ? DK_PEDWARN
: DK_WARNING
);
50 diagnostic
.option_index
= OPT_Wc99_c11_compat
;
51 warned
= diagnostic_report_diagnostic (global_dc
, &diagnostic
);
53 /* -Wno-c99-c11-compat suppresses even the pedwarns. */
54 else if (warn_c99_c11_compat
== 0)
56 /* For -pedantic outside C11, issue a pedwarn. */
57 else if (pedantic
&& !flag_isoc11
)
59 diagnostic_set_info (&diagnostic
, gmsgid
, &ap
, &richloc
, DK_PEDWARN
);
60 diagnostic
.option_index
= opt
;
61 warned
= diagnostic_report_diagnostic (global_dc
, &diagnostic
);
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.) */
75 pedwarn_c90 (location_t location
, int opt
, const char *gmsgid
, ...)
77 diagnostic_info diagnostic
;
80 rich_location
richloc (line_table
, location
);
82 va_start (ap
, gmsgid
);
83 /* Warnings such as -Wvla are the most specific ones. */
84 if (opt
!= OPT_Wpedantic
)
86 int opt_var
= *(int *) option_flag_var (opt
, &global_options
);
91 diagnostic_set_info (&diagnostic
, gmsgid
, &ap
, &richloc
,
92 (pedantic
&& !flag_isoc99
)
93 ? DK_PEDWARN
: DK_WARNING
);
94 diagnostic
.option_index
= opt
;
95 diagnostic_report_diagnostic (global_dc
, &diagnostic
);
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)
104 diagnostic_set_info (&diagnostic
, gmsgid
, &ap
, &richloc
,
105 (pedantic
&& !flag_isoc99
)
106 ? DK_PEDWARN
: DK_WARNING
);
107 diagnostic
.option_index
= OPT_Wc90_c99_compat
;
108 diagnostic_report_diagnostic (global_dc
, &diagnostic
);
110 /* -Wno-c90-c99-compat suppresses the pedwarns. */
111 else if (warn_c90_c99_compat
== 0)
113 /* For -pedantic outside C99, issue a pedwarn. */
114 else if (pedantic
&& !flag_isoc99
)
116 diagnostic_set_info (&diagnostic
, gmsgid
, &ap
, &richloc
, DK_PEDWARN
);
117 diagnostic
.option_index
= opt
;
118 diagnostic_report_diagnostic (global_dc
, &diagnostic
);