c-errors.c 4.01 KB
Newer Older
1
/* Various diagnostic subroutines for the GNU C language.
2
   Copyright (C) 2000-2016 Free Software Foundation, Inc.
3 4
   Contributed by Gabriel Dos Reis <gdr@codesourcery.com>

5
This file is part of GCC.
6

7 8
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
9
Software Foundation; either version 3, or (at your option) any later
10
version.
11

12 13 14 15
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.
16 17

You should have received a copy of the GNU General Public License
18 19
along with GCC; see the file COPYING3.  If not see
<http://www.gnu.org/licenses/>.  */
20 21 22

#include "config.h"
#include "system.h"
23 24
#include "coretypes.h"
#include "tm.h"
25
#include "c-tree.h"
26
#include "opts.h"
27

28 29 30 31 32
/* 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.  */
33

34
bool
35
pedwarn_c99 (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);
Mike Stump committed
41

42
  va_start (ap, gmsgid);
43 44 45 46
  /* If desired, issue the C99/C11 compat warning, which is more specific
     than -pedantic.  */
  if (warn_c99_c11_compat > 0)
    {
47
      diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc,
48 49 50 51 52 53 54 55 56 57 58
			   (pedantic && !flag_isoc11)
			   ? DK_PEDWARN : DK_WARNING);
      diagnostic.option_index = OPT_Wc99_c11_compat;
      warned = report_diagnostic (&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)
    {
59
      diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc, DK_PEDWARN);
60 61 62
      diagnostic.option_index = opt;
      warned = report_diagnostic (&diagnostic);
    }
63
  va_end (ap);
64
  return warned;
65
}
66

67 68 69 70 71 72
/* 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.)  */
73

74
bool
75
pedwarn_c90 (location_t location, int opt, const char *gmsgid, ...)
76 77 78
{
  diagnostic_info diagnostic;
  va_list ap;
79
  bool warned = false;
80
  rich_location richloc (line_table, location);
81

82
  va_start (ap, gmsgid);
83 84
  /* Warnings such as -Wvla are the most specific ones.  */
  if (opt != OPT_Wpedantic)
85
    {
86 87 88 89 90
      int opt_var = *(int *) option_flag_var (opt, &global_options);
      if (opt_var == 0)
        goto out;
      else if (opt_var > 0)
	{
91
	  diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc,
92 93 94 95
			       (pedantic && !flag_isoc99)
			       ? DK_PEDWARN : DK_WARNING);
	  diagnostic.option_index = opt;
	  report_diagnostic (&diagnostic);
96
	  warned = true;
97 98
	  goto out;
	}
99
    }
100 101 102
  /* Maybe we want to issue the C90/C99 compat warning, which is more
     specific than -pedantic.  */
  if (warn_c90_c99_compat > 0)
103
    {
104
      diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc,
105 106 107 108
			   (pedantic && !flag_isoc99)
			   ? DK_PEDWARN : DK_WARNING);
      diagnostic.option_index = OPT_Wc90_c99_compat;
      report_diagnostic (&diagnostic);
109
    }
110 111 112 113 114
  /* -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)
115
    {
116
      diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc, DK_PEDWARN);
117
      diagnostic.option_index = opt;
118
      report_diagnostic (&diagnostic);
119
      warned = true;
120
    }
121
out:
122
  va_end (ap);
123
  return warned;
124
}