]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/c/c-errors.c
genattrtab.c (write_header): Include hash-set.h...
[thirdparty/gcc.git] / gcc / c / c-errors.c
CommitLineData
b9161f44 1/* Various diagnostic subroutines for the GNU C language.
5624e564 2 Copyright (C) 2000-2015 Free Software Foundation, Inc.
b9161f44
GDR
3 Contributed by Gabriel Dos Reis <gdr@codesourcery.com>
4
1322177d 5This file is part of GCC.
b9161f44 6
1322177d
LB
7GCC is free software; you can redistribute it and/or modify it under
8the terms of the GNU General Public License as published by the Free
9dcd6f09 9Software Foundation; either version 3, or (at your option) any later
1322177d 10version.
b9161f44 11
1322177d
LB
12GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or
14FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15for more details.
b9161f44
GDR
16
17You should have received a copy of the GNU General Public License
9dcd6f09
NC
18along with GCC; see the file COPYING3. If not see
19<http://www.gnu.org/licenses/>. */
b9161f44
GDR
20
21#include "config.h"
22#include "system.h"
4977bab6
ZW
23#include "coretypes.h"
24#include "tm.h"
40e23961
MC
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"
b9161f44
GDR
33#include "tree.h"
34#include "c-tree.h"
35#include "tm_p.h"
36#include "flags.h"
37#include "diagnostic.h"
177cce46 38#include "opts.h"
b9161f44 39
35aff4fb
MP
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. */
b9161f44 45
35aff4fb 46bool
509c9d60 47pedwarn_c99 (location_t location, int opt, const char *gmsgid, ...)
b9161f44 48{
47b69537 49 diagnostic_info diagnostic;
e34d07f2 50 va_list ap;
35aff4fb 51 bool warned = false;
c22cacf3 52
4b794eaf 53 va_start (ap, gmsgid);
35aff4fb
MP
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 }
e34d07f2 74 va_end (ap);
35aff4fb 75 return warned;
b9161f44 76}
85617eba 77
f3bede71
MP
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.) */
85617eba
HPN
84
85void
509c9d60 86pedwarn_c90 (location_t location, int opt, const char *gmsgid, ...)
85617eba
HPN
87{
88 diagnostic_info diagnostic;
89 va_list ap;
90
4b794eaf 91 va_start (ap, gmsgid);
177cce46
MP
92 /* Warnings such as -Wvla are the most specific ones. */
93 if (opt != OPT_Wpedantic)
f3bede71 94 {
177cce46
MP
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 }
f3bede71 107 }
177cce46
MP
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)
f3bede71 111 {
177cce46
MP
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);
f3bede71 117 }
177cce46
MP
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)
f3bede71 123 {
177cce46
MP
124 diagnostic_set_info (&diagnostic, gmsgid, &ap, location, DK_PEDWARN);
125 diagnostic.option_index = opt;
f3bede71
MP
126 report_diagnostic (&diagnostic);
127 }
177cce46 128out:
85617eba
HPN
129 va_end (ap);
130}