gcc/c-family/
[official-gcc.git] / gcc / c / c-errors.c
blob89393b9b44d648e5e954b8c4b33a4e584c97c7fc
1 /* Various diagnostic subroutines for the GNU C language.
2 Copyright (C) 2000-2014 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 "tree.h"
26 #include "c-tree.h"
27 #include "tm_p.h"
28 #include "flags.h"
29 #include "diagnostic.h"
30 #include "opts.h"
32 /* Issue an ISO C99 pedantic warning MSGID. */
34 void
35 pedwarn_c99 (location_t location, int opt, const char *gmsgid, ...)
37 diagnostic_info diagnostic;
38 va_list ap;
40 va_start (ap, gmsgid);
41 diagnostic_set_info (&diagnostic, gmsgid, &ap, location,
42 flag_isoc99 ? DK_PEDWARN : DK_WARNING);
43 diagnostic.option_index = opt;
44 report_diagnostic (&diagnostic);
45 va_end (ap);
48 /* Issue an ISO C90 pedantic warning MSGID if -pedantic outside C99 mode,
49 otherwise issue warning MSGID if -Wc90-c99-compat is specified, or if
50 a specific option such as -Wlong-long is specified.
51 This function is supposed to be used for matters that are allowed in
52 ISO C99 but not supported in ISO C90, thus we explicitly don't pedwarn
53 when C99 is specified. (There is no flag_c90.) */
55 void
56 pedwarn_c90 (location_t location, int opt, const char *gmsgid, ...)
58 diagnostic_info diagnostic;
59 va_list ap;
61 va_start (ap, gmsgid);
62 /* Warnings such as -Wvla are the most specific ones. */
63 if (opt != OPT_Wpedantic)
65 int opt_var = *(int *) option_flag_var (opt, &global_options);
66 if (opt_var == 0)
67 goto out;
68 else if (opt_var > 0)
70 diagnostic_set_info (&diagnostic, gmsgid, &ap, location,
71 (pedantic && !flag_isoc99)
72 ? DK_PEDWARN : DK_WARNING);
73 diagnostic.option_index = opt;
74 report_diagnostic (&diagnostic);
75 goto out;
78 /* Maybe we want to issue the C90/C99 compat warning, which is more
79 specific than -pedantic. */
80 if (warn_c90_c99_compat > 0)
82 diagnostic_set_info (&diagnostic, gmsgid, &ap, location,
83 (pedantic && !flag_isoc99)
84 ? DK_PEDWARN : DK_WARNING);
85 diagnostic.option_index = OPT_Wc90_c99_compat;
86 report_diagnostic (&diagnostic);
88 /* -Wno-c90-c99-compat suppresses the pedwarns. */
89 else if (warn_c90_c99_compat == 0)
91 /* For -pedantic outside C99, issue a pedwarn. */
92 else if (pedantic && !flag_isoc99)
94 diagnostic_set_info (&diagnostic, gmsgid, &ap, location, DK_PEDWARN);
95 diagnostic.option_index = opt;
96 report_diagnostic (&diagnostic);
98 out:
99 va_end (ap);