/* Various diagnostic subroutines for the GNU C language.
- Copyright (C) 2000, 2001, 2003, 2007, 2008, 2012
- Free Software Foundation, Inc.
+ Copyright (C) 2000-2017 Free Software Foundation, Inc.
Contributed by Gabriel Dos Reis <gdr@codesourcery.com>
This file is part of GCC.
#include "system.h"
#include "coretypes.h"
#include "tm.h"
-#include "tree.h"
#include "c-tree.h"
-#include "tm_p.h"
-#include "flags.h"
-#include "diagnostic.h"
+#include "opts.h"
-/* Issue an ISO C99 pedantic warning MSGID. */
+/* 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. */
-void
+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);
- diagnostic_set_info (&diagnostic, gmsgid, &ap, location,
- flag_isoc99 ? DK_PEDWARN : DK_WARNING);
- diagnostic.option_index = opt;
- report_diagnostic (&diagnostic);
+ /* 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. 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.) */
+/* 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.) */
-void
+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);
- diagnostic_set_info (&diagnostic, gmsgid, &ap, location,
- flag_isoc99 ? DK_WARNING : DK_PEDWARN);
- diagnostic.option_index = opt;
- report_diagnostic (&diagnostic);
+ /* 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;
}