]>
Commit | Line | Data |
---|---|---|
e8785647 | 1 | /* Various diagnostic subroutines for the GNU C language. |
fbd26352 | 2 | Copyright (C) 2000-2019 Free Software Foundation, Inc. |
e8785647 | 3 | Contributed by Gabriel Dos Reis <gdr@codesourcery.com> |
4 | ||
f12b58b3 | 5 | This file is part of GCC. |
e8785647 | 6 | |
f12b58b3 | 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 | |
8c4c00c1 | 9 | Software Foundation; either version 3, or (at your option) any later |
f12b58b3 | 10 | version. |
e8785647 | 11 | |
f12b58b3 | 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. | |
e8785647 | 16 | |
17 | You should have received a copy of the GNU General Public License | |
8c4c00c1 | 18 | along with GCC; see the file COPYING3. If not see |
19 | <http://www.gnu.org/licenses/>. */ | |
e8785647 | 20 | |
21 | #include "config.h" | |
22 | #include "system.h" | |
805e22b2 | 23 | #include "coretypes.h" |
24 | #include "tm.h" | |
e8785647 | 25 | #include "c-tree.h" |
806fe15e | 26 | #include "opts.h" |
e8785647 | 27 | |
fcbe1d64 | 28 | /* Issue an ISO C11 pedantic warning MSGID if -pedantic outside C2X mode, |
29 | otherwise issue warning MSGID if -Wc11-c2X-compat is specified. | |
30 | This function is supposed to be used for matters that are allowed in | |
31 | ISO C2X but not supported in ISO C11, thus we explicitly don't pedwarn | |
32 | when C2X is specified. */ | |
33 | ||
34 | bool | |
35 | pedwarn_c11 (location_t location, int opt, const char *gmsgid, ...) | |
36 | { | |
37 | diagnostic_info diagnostic; | |
38 | va_list ap; | |
39 | bool warned = false; | |
40 | rich_location richloc (line_table, location); | |
41 | ||
42 | va_start (ap, gmsgid); | |
43 | /* If desired, issue the C11/C2X compat warning, which is more specific | |
44 | than -pedantic. */ | |
45 | if (warn_c11_c2x_compat > 0) | |
46 | { | |
47 | diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc, | |
48 | (pedantic && !flag_isoc2x) | |
49 | ? DK_PEDWARN : DK_WARNING); | |
50 | diagnostic.option_index = OPT_Wc11_c2x_compat; | |
51 | warned = diagnostic_report_diagnostic (global_dc, &diagnostic); | |
52 | } | |
53 | /* -Wno-c11-c2x-compat suppresses even the pedwarns. */ | |
54 | else if (warn_c11_c2x_compat == 0) | |
55 | ; | |
56 | /* For -pedantic outside C2X, issue a pedwarn. */ | |
57 | else if (pedantic && !flag_isoc2x) | |
58 | { | |
59 | diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc, DK_PEDWARN); | |
60 | diagnostic.option_index = opt; | |
61 | warned = diagnostic_report_diagnostic (global_dc, &diagnostic); | |
62 | } | |
63 | va_end (ap); | |
64 | return warned; | |
65 | } | |
66 | ||
508ea33a | 67 | /* Issue an ISO C99 pedantic warning MSGID if -pedantic outside C11 mode, |
68 | otherwise issue warning MSGID if -Wc99-c11-compat is specified. | |
69 | This function is supposed to be used for matters that are allowed in | |
70 | ISO C11 but not supported in ISO C99, thus we explicitly don't pedwarn | |
71 | when C11 is specified. */ | |
e8785647 | 72 | |
508ea33a | 73 | bool |
21ca8540 | 74 | pedwarn_c99 (location_t location, int opt, const char *gmsgid, ...) |
e8785647 | 75 | { |
25e2ffe1 | 76 | diagnostic_info diagnostic; |
ee582a61 | 77 | va_list ap; |
508ea33a | 78 | bool warned = false; |
a96cefb2 | 79 | rich_location richloc (line_table, location); |
a0c938f0 | 80 | |
380c6697 | 81 | va_start (ap, gmsgid); |
508ea33a | 82 | /* If desired, issue the C99/C11 compat warning, which is more specific |
83 | than -pedantic. */ | |
84 | if (warn_c99_c11_compat > 0) | |
85 | { | |
f0479000 | 86 | diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc, |
508ea33a | 87 | (pedantic && !flag_isoc11) |
88 | ? DK_PEDWARN : DK_WARNING); | |
89 | diagnostic.option_index = OPT_Wc99_c11_compat; | |
56b8400f | 90 | warned = diagnostic_report_diagnostic (global_dc, &diagnostic); |
508ea33a | 91 | } |
92 | /* -Wno-c99-c11-compat suppresses even the pedwarns. */ | |
93 | else if (warn_c99_c11_compat == 0) | |
94 | ; | |
95 | /* For -pedantic outside C11, issue a pedwarn. */ | |
96 | else if (pedantic && !flag_isoc11) | |
97 | { | |
f0479000 | 98 | diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc, DK_PEDWARN); |
508ea33a | 99 | diagnostic.option_index = opt; |
56b8400f | 100 | warned = diagnostic_report_diagnostic (global_dc, &diagnostic); |
508ea33a | 101 | } |
ee582a61 | 102 | va_end (ap); |
508ea33a | 103 | return warned; |
e8785647 | 104 | } |
aa267cf6 | 105 | |
890c2e2f | 106 | /* Issue an ISO C90 pedantic warning MSGID if -pedantic outside C99 mode, |
107 | otherwise issue warning MSGID if -Wc90-c99-compat is specified, or if | |
108 | a specific option such as -Wlong-long is specified. | |
109 | This function is supposed to be used for matters that are allowed in | |
110 | ISO C99 but not supported in ISO C90, thus we explicitly don't pedwarn | |
111 | when C99 is specified. (There is no flag_c90.) */ | |
aa267cf6 | 112 | |
54c4d22e | 113 | bool |
21ca8540 | 114 | pedwarn_c90 (location_t location, int opt, const char *gmsgid, ...) |
aa267cf6 | 115 | { |
116 | diagnostic_info diagnostic; | |
117 | va_list ap; | |
54c4d22e | 118 | bool warned = false; |
a96cefb2 | 119 | rich_location richloc (line_table, location); |
aa267cf6 | 120 | |
380c6697 | 121 | va_start (ap, gmsgid); |
806fe15e | 122 | /* Warnings such as -Wvla are the most specific ones. */ |
123 | if (opt != OPT_Wpedantic) | |
890c2e2f | 124 | { |
806fe15e | 125 | int opt_var = *(int *) option_flag_var (opt, &global_options); |
126 | if (opt_var == 0) | |
127 | goto out; | |
128 | else if (opt_var > 0) | |
129 | { | |
f0479000 | 130 | diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc, |
806fe15e | 131 | (pedantic && !flag_isoc99) |
132 | ? DK_PEDWARN : DK_WARNING); | |
133 | diagnostic.option_index = opt; | |
56b8400f | 134 | diagnostic_report_diagnostic (global_dc, &diagnostic); |
54c4d22e | 135 | warned = true; |
806fe15e | 136 | goto out; |
137 | } | |
890c2e2f | 138 | } |
806fe15e | 139 | /* Maybe we want to issue the C90/C99 compat warning, which is more |
140 | specific than -pedantic. */ | |
141 | if (warn_c90_c99_compat > 0) | |
890c2e2f | 142 | { |
f0479000 | 143 | diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc, |
806fe15e | 144 | (pedantic && !flag_isoc99) |
145 | ? DK_PEDWARN : DK_WARNING); | |
146 | diagnostic.option_index = OPT_Wc90_c99_compat; | |
56b8400f | 147 | diagnostic_report_diagnostic (global_dc, &diagnostic); |
890c2e2f | 148 | } |
806fe15e | 149 | /* -Wno-c90-c99-compat suppresses the pedwarns. */ |
150 | else if (warn_c90_c99_compat == 0) | |
151 | ; | |
152 | /* For -pedantic outside C99, issue a pedwarn. */ | |
153 | else if (pedantic && !flag_isoc99) | |
890c2e2f | 154 | { |
f0479000 | 155 | diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc, DK_PEDWARN); |
806fe15e | 156 | diagnostic.option_index = opt; |
56b8400f | 157 | diagnostic_report_diagnostic (global_dc, &diagnostic); |
54c4d22e | 158 | warned = true; |
890c2e2f | 159 | } |
806fe15e | 160 | out: |
aa267cf6 | 161 | va_end (ap); |
54c4d22e | 162 | return warned; |
aa267cf6 | 163 | } |