xref: /netbsd-src/external/gpl3/gcc.old/dist/gcc/c/c-errors.c (revision c9496f6b604074a9451a67df576a5b423068e71e)
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>
4 
5 This file is part of GCC.
6 
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.
11 
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.
16 
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/>.  */
20 
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "tm.h"
25 #include "hash-set.h"
26 #include "vec.h"
27 #include "symtab.h"
28 #include "input.h"
29 #include "alias.h"
30 #include "double-int.h"
31 #include "machmode.h"
32 #include "inchash.h"
33 #include "tree.h"
34 #include "c-tree.h"
35 #include "tm_p.h"
36 #include "flags.h"
37 #include "diagnostic.h"
38 #include "opts.h"
39 
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.  */
45 
46 bool
47 pedwarn_c99 (location_t location, int opt, const char *gmsgid, ...)
48 {
49   diagnostic_info diagnostic;
50   va_list ap;
51   bool warned = false;
52 
53   va_start (ap, gmsgid);
54   /* If desired, issue the C99/C11 compat warning, which is more specific
55      than -pedantic.  */
56   if (warn_c99_c11_compat > 0)
57     {
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);
63     }
64   /* -Wno-c99-c11-compat suppresses even the pedwarns.  */
65   else if (warn_c99_c11_compat == 0)
66     ;
67   /* For -pedantic outside C11, issue a pedwarn.  */
68   else if (pedantic && !flag_isoc11)
69     {
70       diagnostic_set_info (&diagnostic, gmsgid, &ap, location, DK_PEDWARN);
71       diagnostic.option_index = opt;
72       warned = report_diagnostic (&diagnostic);
73     }
74   va_end (ap);
75   return warned;
76 }
77 
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.)  */
84 
85 void
86 pedwarn_c90 (location_t location, int opt, const char *gmsgid, ...)
87 {
88   diagnostic_info diagnostic;
89   va_list ap;
90 
91   va_start (ap, gmsgid);
92   /* Warnings such as -Wvla are the most specific ones.  */
93   if (opt != OPT_Wpedantic)
94     {
95       int opt_var = *(int *) option_flag_var (opt, &global_options);
96       if (opt_var == 0)
97         goto out;
98       else if (opt_var > 0)
99 	{
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);
105 	  goto out;
106 	}
107     }
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)
111     {
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);
117     }
118   /* -Wno-c90-c99-compat suppresses the pedwarns.  */
119   else if (warn_c90_c99_compat == 0)
120     ;
121   /* For -pedantic outside C99, issue a pedwarn.  */
122   else if (pedantic && !flag_isoc99)
123     {
124       diagnostic_set_info (&diagnostic, gmsgid, &ap, location, DK_PEDWARN);
125       diagnostic.option_index = opt;
126       report_diagnostic (&diagnostic);
127     }
128 out:
129   va_end (ap);
130 }
131