xref: /dflybsd-src/contrib/gcc-8.0/gcc/c/c-errors.c (revision 38fd149817dfbff97799f62fcb70be98c4e32523)
1*38fd1498Szrj /* Various diagnostic subroutines for the GNU C language.
2*38fd1498Szrj    Copyright (C) 2000-2018 Free Software Foundation, Inc.
3*38fd1498Szrj    Contributed by Gabriel Dos Reis <gdr@codesourcery.com>
4*38fd1498Szrj 
5*38fd1498Szrj This file is part of GCC.
6*38fd1498Szrj 
7*38fd1498Szrj GCC is free software; you can redistribute it and/or modify it under
8*38fd1498Szrj the terms of the GNU General Public License as published by the Free
9*38fd1498Szrj Software Foundation; either version 3, or (at your option) any later
10*38fd1498Szrj version.
11*38fd1498Szrj 
12*38fd1498Szrj GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13*38fd1498Szrj WARRANTY; without even the implied warranty of MERCHANTABILITY or
14*38fd1498Szrj FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15*38fd1498Szrj for more details.
16*38fd1498Szrj 
17*38fd1498Szrj You should have received a copy of the GNU General Public License
18*38fd1498Szrj along with GCC; see the file COPYING3.  If not see
19*38fd1498Szrj <http://www.gnu.org/licenses/>.  */
20*38fd1498Szrj 
21*38fd1498Szrj #include "config.h"
22*38fd1498Szrj #include "system.h"
23*38fd1498Szrj #include "coretypes.h"
24*38fd1498Szrj #include "tm.h"
25*38fd1498Szrj #include "c-tree.h"
26*38fd1498Szrj #include "opts.h"
27*38fd1498Szrj 
28*38fd1498Szrj /* Issue an ISO C99 pedantic warning MSGID if -pedantic outside C11 mode,
29*38fd1498Szrj    otherwise issue warning MSGID if -Wc99-c11-compat is specified.
30*38fd1498Szrj    This function is supposed to be used for matters that are allowed in
31*38fd1498Szrj    ISO C11 but not supported in ISO C99, thus we explicitly don't pedwarn
32*38fd1498Szrj    when C11 is specified.  */
33*38fd1498Szrj 
34*38fd1498Szrj bool
pedwarn_c99(location_t location,int opt,const char * gmsgid,...)35*38fd1498Szrj pedwarn_c99 (location_t location, int opt, const char *gmsgid, ...)
36*38fd1498Szrj {
37*38fd1498Szrj   diagnostic_info diagnostic;
38*38fd1498Szrj   va_list ap;
39*38fd1498Szrj   bool warned = false;
40*38fd1498Szrj   rich_location richloc (line_table, location);
41*38fd1498Szrj 
42*38fd1498Szrj   va_start (ap, gmsgid);
43*38fd1498Szrj   /* If desired, issue the C99/C11 compat warning, which is more specific
44*38fd1498Szrj      than -pedantic.  */
45*38fd1498Szrj   if (warn_c99_c11_compat > 0)
46*38fd1498Szrj     {
47*38fd1498Szrj       diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc,
48*38fd1498Szrj 			   (pedantic && !flag_isoc11)
49*38fd1498Szrj 			   ? DK_PEDWARN : DK_WARNING);
50*38fd1498Szrj       diagnostic.option_index = OPT_Wc99_c11_compat;
51*38fd1498Szrj       warned = diagnostic_report_diagnostic (global_dc, &diagnostic);
52*38fd1498Szrj     }
53*38fd1498Szrj   /* -Wno-c99-c11-compat suppresses even the pedwarns.  */
54*38fd1498Szrj   else if (warn_c99_c11_compat == 0)
55*38fd1498Szrj     ;
56*38fd1498Szrj   /* For -pedantic outside C11, issue a pedwarn.  */
57*38fd1498Szrj   else if (pedantic && !flag_isoc11)
58*38fd1498Szrj     {
59*38fd1498Szrj       diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc, DK_PEDWARN);
60*38fd1498Szrj       diagnostic.option_index = opt;
61*38fd1498Szrj       warned = diagnostic_report_diagnostic (global_dc, &diagnostic);
62*38fd1498Szrj     }
63*38fd1498Szrj   va_end (ap);
64*38fd1498Szrj   return warned;
65*38fd1498Szrj }
66*38fd1498Szrj 
67*38fd1498Szrj /* Issue an ISO C90 pedantic warning MSGID if -pedantic outside C99 mode,
68*38fd1498Szrj    otherwise issue warning MSGID if -Wc90-c99-compat is specified, or if
69*38fd1498Szrj    a specific option such as -Wlong-long is specified.
70*38fd1498Szrj    This function is supposed to be used for matters that are allowed in
71*38fd1498Szrj    ISO C99 but not supported in ISO C90, thus we explicitly don't pedwarn
72*38fd1498Szrj    when C99 is specified.  (There is no flag_c90.)  */
73*38fd1498Szrj 
74*38fd1498Szrj bool
pedwarn_c90(location_t location,int opt,const char * gmsgid,...)75*38fd1498Szrj pedwarn_c90 (location_t location, int opt, const char *gmsgid, ...)
76*38fd1498Szrj {
77*38fd1498Szrj   diagnostic_info diagnostic;
78*38fd1498Szrj   va_list ap;
79*38fd1498Szrj   bool warned = false;
80*38fd1498Szrj   rich_location richloc (line_table, location);
81*38fd1498Szrj 
82*38fd1498Szrj   va_start (ap, gmsgid);
83*38fd1498Szrj   /* Warnings such as -Wvla are the most specific ones.  */
84*38fd1498Szrj   if (opt != OPT_Wpedantic)
85*38fd1498Szrj     {
86*38fd1498Szrj       int opt_var = *(int *) option_flag_var (opt, &global_options);
87*38fd1498Szrj       if (opt_var == 0)
88*38fd1498Szrj         goto out;
89*38fd1498Szrj       else if (opt_var > 0)
90*38fd1498Szrj 	{
91*38fd1498Szrj 	  diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc,
92*38fd1498Szrj 			       (pedantic && !flag_isoc99)
93*38fd1498Szrj 			       ? DK_PEDWARN : DK_WARNING);
94*38fd1498Szrj 	  diagnostic.option_index = opt;
95*38fd1498Szrj 	  diagnostic_report_diagnostic (global_dc, &diagnostic);
96*38fd1498Szrj 	  warned = true;
97*38fd1498Szrj 	  goto out;
98*38fd1498Szrj 	}
99*38fd1498Szrj     }
100*38fd1498Szrj   /* Maybe we want to issue the C90/C99 compat warning, which is more
101*38fd1498Szrj      specific than -pedantic.  */
102*38fd1498Szrj   if (warn_c90_c99_compat > 0)
103*38fd1498Szrj     {
104*38fd1498Szrj       diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc,
105*38fd1498Szrj 			   (pedantic && !flag_isoc99)
106*38fd1498Szrj 			   ? DK_PEDWARN : DK_WARNING);
107*38fd1498Szrj       diagnostic.option_index = OPT_Wc90_c99_compat;
108*38fd1498Szrj       diagnostic_report_diagnostic (global_dc, &diagnostic);
109*38fd1498Szrj     }
110*38fd1498Szrj   /* -Wno-c90-c99-compat suppresses the pedwarns.  */
111*38fd1498Szrj   else if (warn_c90_c99_compat == 0)
112*38fd1498Szrj     ;
113*38fd1498Szrj   /* For -pedantic outside C99, issue a pedwarn.  */
114*38fd1498Szrj   else if (pedantic && !flag_isoc99)
115*38fd1498Szrj     {
116*38fd1498Szrj       diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc, DK_PEDWARN);
117*38fd1498Szrj       diagnostic.option_index = opt;
118*38fd1498Szrj       diagnostic_report_diagnostic (global_dc, &diagnostic);
119*38fd1498Szrj       warned = true;
120*38fd1498Szrj     }
121*38fd1498Szrj out:
122*38fd1498Szrj   va_end (ap);
123*38fd1498Szrj   return warned;
124*38fd1498Szrj }
125