2015-06-25 Zhouyi Zhou <yizhouzhou@ict.ac.cn>
[official-gcc.git] / gcc / c / c-errors.c
blob1c1a1da97e44d8c5e5b8e1e6b660ca1b0e8080c9
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
10 version.
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.
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 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "tm.h"
25 #include "symtab.h"
26 #include "alias.h"
27 #include "tree.h"
28 #include "c-tree.h"
29 #include "tm_p.h"
30 #include "flags.h"
31 #include "diagnostic.h"
32 #include "opts.h"
34 /* Issue an ISO C99 pedantic warning MSGID if -pedantic outside C11 mode,
35 otherwise issue warning MSGID if -Wc99-c11-compat is specified.
36 This function is supposed to be used for matters that are allowed in
37 ISO C11 but not supported in ISO C99, thus we explicitly don't pedwarn
38 when C11 is specified. */
40 bool
41 pedwarn_c99 (location_t location, int opt, const char *gmsgid, ...)
43 diagnostic_info diagnostic;
44 va_list ap;
45 bool warned = false;
47 va_start (ap, gmsgid);
48 /* If desired, issue the C99/C11 compat warning, which is more specific
49 than -pedantic. */
50 if (warn_c99_c11_compat > 0)
52 diagnostic_set_info (&diagnostic, gmsgid, &ap, location,
53 (pedantic && !flag_isoc11)
54 ? DK_PEDWARN : DK_WARNING);
55 diagnostic.option_index = OPT_Wc99_c11_compat;
56 warned = report_diagnostic (&diagnostic);
58 /* -Wno-c99-c11-compat suppresses even the pedwarns. */
59 else if (warn_c99_c11_compat == 0)
61 /* For -pedantic outside C11, issue a pedwarn. */
62 else if (pedantic && !flag_isoc11)
64 diagnostic_set_info (&diagnostic, gmsgid, &ap, location, DK_PEDWARN);
65 diagnostic.option_index = opt;
66 warned = report_diagnostic (&diagnostic);
68 va_end (ap);
69 return warned;
72 /* Issue an ISO C90 pedantic warning MSGID if -pedantic outside C99 mode,
73 otherwise issue warning MSGID if -Wc90-c99-compat is specified, or if
74 a specific option such as -Wlong-long is specified.
75 This function is supposed to be used for matters that are allowed in
76 ISO C99 but not supported in ISO C90, thus we explicitly don't pedwarn
77 when C99 is specified. (There is no flag_c90.) */
79 void
80 pedwarn_c90 (location_t location, int opt, const char *gmsgid, ...)
82 diagnostic_info diagnostic;
83 va_list ap;
85 va_start (ap, gmsgid);
86 /* Warnings such as -Wvla are the most specific ones. */
87 if (opt != OPT_Wpedantic)
89 int opt_var = *(int *) option_flag_var (opt, &global_options);
90 if (opt_var == 0)
91 goto out;
92 else if (opt_var > 0)
94 diagnostic_set_info (&diagnostic, gmsgid, &ap, location,
95 (pedantic && !flag_isoc99)
96 ? DK_PEDWARN : DK_WARNING);
97 diagnostic.option_index = opt;
98 report_diagnostic (&diagnostic);
99 goto out;
102 /* Maybe we want to issue the C90/C99 compat warning, which is more
103 specific than -pedantic. */
104 if (warn_c90_c99_compat > 0)
106 diagnostic_set_info (&diagnostic, gmsgid, &ap, location,
107 (pedantic && !flag_isoc99)
108 ? DK_PEDWARN : DK_WARNING);
109 diagnostic.option_index = OPT_Wc90_c99_compat;
110 report_diagnostic (&diagnostic);
112 /* -Wno-c90-c99-compat suppresses the pedwarns. */
113 else if (warn_c90_c99_compat == 0)
115 /* For -pedantic outside C99, issue a pedwarn. */
116 else if (pedantic && !flag_isoc99)
118 diagnostic_set_info (&diagnostic, gmsgid, &ap, location, DK_PEDWARN);
119 diagnostic.option_index = opt;
120 report_diagnostic (&diagnostic);
122 out:
123 va_end (ap);