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