1 /* Various diagnostic subroutines for the GNU C language.
2 Copyright (C) 2000-2015 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"
30 #include "double-int.h"
37 #include "diagnostic.h"
40 /* Issue an ISO C99 pedantic warning MSGID if -pedantic outside C11 mode,
41 otherwise issue warning MSGID if -Wc99-c11-compat is specified.
42 This function is supposed to be used for matters that are allowed in
43 ISO C11 but not supported in ISO C99, thus we explicitly don't pedwarn
44 when C11 is specified. */
47 pedwarn_c99 (location_t location
, int opt
, const char *gmsgid
, ...)
49 diagnostic_info diagnostic
;
53 va_start (ap
, gmsgid
);
54 /* If desired, issue the C99/C11 compat warning, which is more specific
56 if (warn_c99_c11_compat
> 0)
58 diagnostic_set_info (&diagnostic
, gmsgid
, &ap
, location
,
59 (pedantic
&& !flag_isoc11
)
60 ? DK_PEDWARN
: DK_WARNING
);
61 diagnostic
.option_index
= OPT_Wc99_c11_compat
;
62 warned
= report_diagnostic (&diagnostic
);
64 /* -Wno-c99-c11-compat suppresses even the pedwarns. */
65 else if (warn_c99_c11_compat
== 0)
67 /* For -pedantic outside C11, issue a pedwarn. */
68 else if (pedantic
&& !flag_isoc11
)
70 diagnostic_set_info (&diagnostic
, gmsgid
, &ap
, location
, DK_PEDWARN
);
71 diagnostic
.option_index
= opt
;
72 warned
= report_diagnostic (&diagnostic
);
78 /* Issue an ISO C90 pedantic warning MSGID if -pedantic outside C99 mode,
79 otherwise issue warning MSGID if -Wc90-c99-compat is specified, or if
80 a specific option such as -Wlong-long is specified.
81 This function is supposed to be used for matters that are allowed in
82 ISO C99 but not supported in ISO C90, thus we explicitly don't pedwarn
83 when C99 is specified. (There is no flag_c90.) */
86 pedwarn_c90 (location_t location
, int opt
, const char *gmsgid
, ...)
88 diagnostic_info diagnostic
;
91 va_start (ap
, gmsgid
);
92 /* Warnings such as -Wvla are the most specific ones. */
93 if (opt
!= OPT_Wpedantic
)
95 int opt_var
= *(int *) option_flag_var (opt
, &global_options
);
100 diagnostic_set_info (&diagnostic
, gmsgid
, &ap
, location
,
101 (pedantic
&& !flag_isoc99
)
102 ? DK_PEDWARN
: DK_WARNING
);
103 diagnostic
.option_index
= opt
;
104 report_diagnostic (&diagnostic
);
108 /* Maybe we want to issue the C90/C99 compat warning, which is more
109 specific than -pedantic. */
110 if (warn_c90_c99_compat
> 0)
112 diagnostic_set_info (&diagnostic
, gmsgid
, &ap
, location
,
113 (pedantic
&& !flag_isoc99
)
114 ? DK_PEDWARN
: DK_WARNING
);
115 diagnostic
.option_index
= OPT_Wc90_c99_compat
;
116 report_diagnostic (&diagnostic
);
118 /* -Wno-c90-c99-compat suppresses the pedwarns. */
119 else if (warn_c90_c99_compat
== 0)
121 /* For -pedantic outside C99, issue a pedwarn. */
122 else if (pedantic
&& !flag_isoc99
)
124 diagnostic_set_info (&diagnostic
, gmsgid
, &ap
, location
, DK_PEDWARN
);
125 diagnostic
.option_index
= opt
;
126 report_diagnostic (&diagnostic
);