This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[c/c++] PR35058: -Werror= works only with some warnings
- From: "Manuel López-Ibáñez" <lopezibanez at gmail dot com>
- To: gcc-patches <gcc-patches at gcc dot gnu dot org>, "Gabriel Dos Reis" <gdr at integrable-solutions dot net>, "Joseph S. Myers" <joseph at codesourcery dot com>, "Mark Mitchell" <mark at codesourcery dot com>
- Date: Tue, 22 Jul 2008 16:34:26 +0200
- Subject: [c/c++] PR35058: -Werror= works only with some warnings
The following patches implement pedwarn (OPT_*, ...) and pedwarn0() as
discussed here:
http://gcc.gnu.org/ml/gcc-patches/2008-02/msg00972.html
This also fixes PR 35058.
Bootstrapped with --enable-languages=all and regression tested on
x86_64-unknown-linux-gnu.
I have broken up the patch so it can be reviewed more easily into
diagnostics, C front-end, C++ front-end and Fortran parts. The fortran
bits were already approved.
OK for 4.4?
Cheers,
Manuel.
2008-07-22 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
PR 35058
* diagnostic.c (pedwarn): Add opt parameter.
(pedwarn0): New.
* c-tree.h (pedwarn_init): Add opt parameter.
(pedwarn_c90): Likewise.
(pedwarn_c99): Likewise.
* c-errors.c (pedwarn_c99): Likewise.
(pedwarn_c90): Likewise.
* toplev.h (pedwarn): Update declaration.
(pedwarn0): Declare.
* All callers changed.
fortran/
* f95-lang.c (gfc_mark_addressable): All callers changed.
cp/
* All callers changed.
testsuite/
* gcc.dg/Wdeclaration-after-statement-3.c: New.
* gcc/testsuite/gcc.dg/Wpointer-arith.c: New.
Index: gcc/diagnostic.c
===================================================================
--- gcc/diagnostic.c (revision 138044)
+++ gcc/diagnostic.c (working copy)
@@ -520,20 +520,38 @@ warning_at (location_t location, int opt
this for diagnostics required by the relevant language standard,
if you have chosen not to make them errors.
Note that these diagnostics are issued independent of the setting
of the -pedantic command-line switch. To get a warning enabled
- only with that switch, write "if (pedantic) pedwarn (...);" */
+ only with that switch, use either "if (pedantic) pedwarn
+ (OPT_pedantic,...)" or just "pedwarn (OPT_pedantic,..)". To get a
+ pedwarn independently of the -pedantic switch use "pedwarn (0,...)". */
+
+void
+pedwarn (int opt, const char *gmsgid, ...)
+{
+ diagnostic_info diagnostic;
+ va_list ap;
+
+ va_start (ap, gmsgid);
+ diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location,
+ pedantic_warning_kind ());
+ diagnostic.option_index = opt;
+
+ report_diagnostic (&diagnostic);
+ va_end (ap);
+}
+
void
-pedwarn (const char *gmsgid, ...)
+pedwarn0 (const char *gmsgid, ...)
{
diagnostic_info diagnostic;
va_list ap;
va_start (ap, gmsgid);
diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location,
- pedantic_warning_kind ());
+ pedantic_warning_kind ());
report_diagnostic (&diagnostic);
va_end (ap);
}
/* A "permissive" error: issues an error unless -fpermissive was given
Index: gcc/toplev.h
===================================================================
--- gcc/toplev.h (revision 138044)
+++ gcc/toplev.h (working copy)
@@ -62,11 +62,13 @@ extern void warning (int, const char *,
extern void warning_at (location_t, int, const char *, ...)
ATTRIBUTE_GCC_DIAG(3,4);
extern void error (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2);
extern void fatal_error (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2)
ATTRIBUTE_NORETURN;
-extern void pedwarn (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2);
+extern void pedwarn0 (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2);
+/* Pass one of the OPT_W* from options.h as the first parameter. */
+extern void pedwarn (int, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3);
extern void permerror (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2);
extern void sorry (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2);
extern void inform (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2);
extern void verbatim (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2);
Index: gcc/c-errors.c
===================================================================
--- gcc/c-errors.c (revision 138044)
+++ gcc/c-errors.c (working copy)
@@ -29,34 +29,36 @@ along with GCC; see the file COPYING3.
#include "diagnostic.h"
/* Issue an ISO C99 pedantic warning MSGID. */
void
-pedwarn_c99 (const char *gmsgid, ...)
+pedwarn_c99 (int opt, const char *gmsgid, ...)
{
diagnostic_info diagnostic;
va_list ap;
va_start (ap, gmsgid);
diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location,
flag_isoc99 ? pedantic_warning_kind () : DK_WARNING);
+ diagnostic.option_index = opt;
report_diagnostic (&diagnostic);
va_end (ap);
}
/* 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.) */
void
-pedwarn_c90 (const char *gmsgid, ...)
+pedwarn_c90 (int opt, const char *gmsgid, ...)
{
diagnostic_info diagnostic;
va_list ap;
va_start (ap, gmsgid);
diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location,
flag_isoc99 ? DK_WARNING : pedantic_warning_kind ());
+ diagnostic.option_index = opt;
report_diagnostic (&diagnostic);
va_end (ap);
}
Index: gcc/c-tree.h
===================================================================
--- gcc/c-tree.h (revision 138044)
+++ gcc/c-tree.h (working copy)
@@ -561,11 +561,11 @@ extern tree build_conditional_expr (tree
extern tree build_compound_expr (tree, tree);
extern tree c_cast_expr (struct c_type_name *, tree);
extern tree build_c_cast (tree, tree);
extern void store_init_value (tree, tree);
extern void error_init (const char *);
-extern void pedwarn_init (const char *);
+extern void pedwarn_init (int opt, const char *);
extern void maybe_warn_string_init (tree, struct c_expr);
extern void start_init (tree, tree, int);
extern void finish_init (void);
extern void really_start_incremental_init (tree);
extern void push_init_level (int);
@@ -638,9 +638,9 @@ extern void c_write_global_declarations
#define ATTRIBUTE_GCC_CDIAG(m, n) __attribute__ ((__format__ (GCC_DIAG_STYLE, m ,n))) ATTRIBUTE_NONNULL(m)
#else
#define ATTRIBUTE_GCC_CDIAG(m, n) ATTRIBUTE_NONNULL(m)
#endif
-extern void pedwarn_c90 (const char *, ...) ATTRIBUTE_GCC_CDIAG(1,2);
-extern void pedwarn_c99 (const char *, ...) ATTRIBUTE_GCC_CDIAG(1,2);
+extern void pedwarn_c90 (int opt, const char *, ...) ATTRIBUTE_GCC_CDIAG(2,3);
+extern void pedwarn_c99 (int opt, const char *, ...) ATTRIBUTE_GCC_CDIAG(2,3);
#endif /* ! GCC_C_TREE_H */
Index: gcc/c-lex.c
===================================================================
--- gcc/c-lex.c (revision 138044)
+++ gcc/c-lex.c (working copy)
@@ -585,12 +585,12 @@ interpret_integer (const cpp_token *toke
type = integer_types[itk];
if (itk > itk_unsigned_long
&& (flags & CPP_N_WIDTH) != CPP_N_LARGE
&& !in_system_header && !flag_isoc99)
- pedwarn ("integer constant is too large for %qs type",
- (flags & CPP_N_UNSIGNED) ? "unsigned long" : "long");
+ pedwarn (0, "integer constant is too large for %qs type",
+ (flags & CPP_N_UNSIGNED) ? "unsigned long" : "long");
value = build_int_cst_wide (type, integer.low, integer.high);
/* Convert imaginary to a complex type. */
if (flags & CPP_N_IMAGINARY)
@@ -639,12 +639,12 @@ interpret_float (const cpp_token *token,
error ("unsupported non-standard suffix on floating constant");
errorcount++;
return error_mark_node;
}
- else if (pedantic)
- pedwarn ("non-standard suffix on floating constant");
+ else
+ pedwarn (OPT_pedantic, "non-standard suffix on floating constant");
type = c_common_type_for_mode (mode, 0);
gcc_assert (type);
}
else if ((flags & CPP_N_WIDTH) == CPP_N_LARGE)
@@ -682,11 +682,11 @@ interpret_float (const cpp_token *token,
have __builtin_inf* to produce an infinity, this is now a
mandatory pedwarn if the target does not support infinities. */
if (REAL_VALUE_ISINF (real))
{
if (!MODE_HAS_INFINITIES (TYPE_MODE (type)))
- pedwarn ("floating constant exceeds range of %qT", type);
+ pedwarn (0, "floating constant exceeds range of %qT", type);
else
warning (OPT_Woverflow, "floating constant exceeds range of %qT", type);
}
/* We also give a warning if the value underflows. */
else if (REAL_VALUES_EQUAL (real, dconst0))
Index: gcc/builtins.c
===================================================================
--- gcc/builtins.c (revision 138044)
+++ gcc/builtins.c (working copy)
@@ -7246,11 +7246,11 @@ fold_builtin_inf (tree type, int warn)
time", footnote "In this case, using INFINITY will violate the
constraint in 6.4.4 and thus require a diagnostic." (C99 7.12#4).
Thus we pedwarn to ensure this constraint violation is
diagnosed. */
if (!MODE_HAS_INFINITIES (TYPE_MODE (type)) && warn)
- pedwarn ("target format does not support infinity");
+ pedwarn (0, "target format does not support infinity");
real_inf (&real);
return build_real (type, real);
}
Index: gcc/toplev.c
===================================================================
--- gcc/toplev.c (revision 138044)
+++ gcc/toplev.c (working copy)
@@ -823,11 +823,11 @@ check_global_declaration_1 (tree decl)
&& ! TREE_PUBLIC (decl)
&& (warn_unused_function
|| TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
{
if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
- pedwarn ("%q+F used but never defined", decl);
+ pedwarn (0, "%q+F used but never defined", decl);
else
warning (OPT_Wunused_function, "%q+F declared %<static%> but never defined", decl);
/* This symbol is effectively an "extern" declaration now. */
TREE_PUBLIC (decl) = 1;
assemble_external (decl);
Index: gcc/testsuite/gcc.dg/Wdeclaration-after-statement-3.c
===================================================================
--- gcc/testsuite/gcc.dg/Wdeclaration-after-statement-3.c (revision 0)
+++ gcc/testsuite/gcc.dg/Wdeclaration-after-statement-3.c (revision 0)
@@ -0,0 +1,24 @@
+/* PR 35058: -Werror= works only with some warnings. */
+/* { dg-do compile } */
+/* { dg-options "-std=c99 -pedantic -Werror=declaration-after-statement" } */
+
+extern void abort (void);
+extern void exit (int);
+
+int
+main (void)
+{
+ int i = 0;
+ if (i != 0)
+ abort ();
+ i++;
+ if (i != 1)
+ abort ();
+ int j = i; /* { dg-error "" "declaration-after-statement" } */
+ if (j != 1)
+ abort ();
+ struct foo { int i0; } k = { 4 }; /* { dg-error "" "declaration-after-statement" } */
+ if (k.i0 != 4)
+ abort ();
+ exit (0);
+}
Index: gcc/testsuite/gcc.dg/Wpointer-arith.c
===================================================================
--- gcc/testsuite/gcc.dg/Wpointer-arith.c (revision 0)
+++ gcc/testsuite/gcc.dg/Wpointer-arith.c (revision 0)
@@ -0,0 +1,10 @@
+/* PR 35058: -Werror= works only with some warnings. */
+/* { dg-do compile } */
+/* { dg-options "-Werror=pointer-arith" } */
+void *a;
+
+void *test(){
+ int x=5;
+ if(a) a++; /* { dg-error "wrong type argument to increment" } */
+ return a+x; /* { dg-error "pointer of type" } */
+}
Index: gcc/c-decl.c
===================================================================
--- gcc/c-decl.c (revision 138044)
+++ gcc/c-decl.c (working copy)
@@ -784,11 +784,11 @@ pop_scope (void)
same translation unit." */
else if (DECL_DECLARED_INLINE_P (p)
&& TREE_PUBLIC (p)
&& !DECL_INITIAL (p)
&& !flag_gnu89_inline)
- pedwarn ("inline function %q+D declared but never defined", p);
+ pedwarn (0, "inline function %q+D declared but never defined", p);
goto common_symbol;
case VAR_DECL:
/* Warnings for unused variables. */
@@ -1221,11 +1221,11 @@ diagnose_mismatched_decls (tree newdecl,
else if (TREE_CODE (newdecl) == FUNCTION_DECL && DECL_INITIAL (newdecl)
&& TYPE_MAIN_VARIANT (TREE_TYPE (oldtype)) == void_type_node
&& TYPE_MAIN_VARIANT (TREE_TYPE (newtype)) == integer_type_node
&& C_FUNCTION_IMPLICIT_INT (newdecl) && !DECL_INITIAL (olddecl))
{
- pedwarn ("conflicting types for %q+D", newdecl);
+ pedwarn (0, "conflicting types for %q+D", newdecl);
/* Make sure we keep void as the return type. */
TREE_TYPE (newdecl) = *newtypep = newtype = oldtype;
C_FUNCTION_IMPLICIT_INT (newdecl) = 0;
pedwarned = true;
}
@@ -1234,11 +1234,11 @@ diagnose_mismatched_decls (tree newdecl,
else if (TREE_CODE (newdecl) == FUNCTION_DECL
&& TYPE_MAIN_VARIANT (TREE_TYPE (newtype)) == void_type_node
&& TYPE_MAIN_VARIANT (TREE_TYPE (oldtype)) == integer_type_node
&& C_DECL_IMPLICIT (olddecl) && !DECL_INITIAL (olddecl))
{
- pedwarn ("conflicting types for %q+D", newdecl);
+ pedwarn (0, "conflicting types for %q+D", newdecl);
/* Make sure we keep void as the return type. */
TREE_TYPE (olddecl) = *oldtypep = oldtype = newtype;
pedwarned = true;
}
else
@@ -1586,11 +1586,11 @@ diagnose_mismatched_decls (tree newdecl,
warned = true;
}
/* Report location of previous decl/defn in a consistent manner. */
if (warned || pedwarned)
- locate_old_decl (olddecl, pedwarned ? pedwarn : warning0);
+ locate_old_decl (olddecl, pedwarned ? pedwarn0 : warning0);
#undef DECL_EXTERN_INLINE
return retval;
}
@@ -2343,11 +2343,12 @@ static void
implicit_decl_warning (tree id, tree olddecl)
{
if (warn_implicit_function_declaration)
{
if (flag_isoc99)
- pedwarn (G_("implicit declaration of function %qE"), id);
+ pedwarn (OPT_Wimplicit_function_declaration,
+ G_("implicit declaration of function %qE"), id);
else
warning (OPT_Wimplicit_function_declaration,
G_("implicit declaration of function %qE"), id);
if (olddecl)
locate_old_decl (olddecl, inform);
@@ -2895,31 +2896,31 @@ shadow_tag_warned (const struct c_declsp
if (name == 0)
{
if (warned != 1 && code != ENUMERAL_TYPE)
/* Empty unnamed enum OK */
{
- pedwarn ("unnamed struct/union that defines no instances");
+ pedwarn (0, "unnamed struct/union that defines no instances");
warned = 1;
}
}
else if (!declspecs->tag_defined_p
&& declspecs->storage_class != csc_none)
{
if (warned != 1)
- pedwarn ("empty declaration with storage class specifier "
- "does not redeclare tag");
+ pedwarn (0, "empty declaration with storage class specifier "
+ "does not redeclare tag");
warned = 1;
pending_xref_error ();
}
else if (!declspecs->tag_defined_p
&& (declspecs->const_p
|| declspecs->volatile_p
|| declspecs->restrict_p))
{
if (warned != 1)
- pedwarn ("empty declaration with type qualifier "
- "does not redeclare tag");
+ pedwarn (0, "empty declaration with type qualifier "
+ "does not redeclare tag");
warned = 1;
pending_xref_error ();
}
else
{
@@ -2935,18 +2936,18 @@ shadow_tag_warned (const struct c_declsp
}
else
{
if (warned != 1 && !in_system_header)
{
- pedwarn ("useless type name in empty declaration");
+ pedwarn (0, "useless type name in empty declaration");
warned = 1;
}
}
}
else if (warned != 1 && !in_system_header && declspecs->typedef_p)
{
- pedwarn ("useless type name in empty declaration");
+ pedwarn (0, "useless type name in empty declaration");
warned = 1;
}
pending_invalid_xref = 0;
@@ -2989,11 +2990,11 @@ shadow_tag_warned (const struct c_declsp
}
if (warned != 1)
{
if (!found_tag)
- pedwarn ("empty declaration");
+ pedwarn (0, "empty declaration");
}
}
/* Return the qualifiers from SPECS as a bitwise OR of TYPE_QUAL_*
@@ -3052,17 +3053,17 @@ build_array_declarator (tree expr, struc
declarator->u.array.attrs = NULL_TREE;
declarator->u.array.quals = 0;
}
declarator->u.array.static_p = static_p;
declarator->u.array.vla_unspec_p = vla_unspec_p;
- if (pedantic && !flag_isoc99)
+ if (!flag_isoc99)
{
if (static_p || quals != NULL)
- pedwarn ("ISO C90 does not support %<static%> or type "
+ pedwarn (OPT_pedantic, "ISO C90 does not support %<static%> or type "
"qualifiers in parameter array declarators");
if (vla_unspec_p)
- pedwarn ("ISO C90 does not support %<[*]%> array declarators");
+ pedwarn (OPT_pedantic, "ISO C90 does not support %<[*]%> array declarators");
}
if (vla_unspec_p)
{
if (!current_scope->parm_flag)
{
@@ -3314,12 +3315,12 @@ start_decl (struct c_declarator *declara
&& current_scope != file_scope
&& TREE_STATIC (decl)
&& !TREE_READONLY (decl)
&& DECL_DECLARED_INLINE_P (current_function_decl)
&& DECL_EXTERNAL (current_function_decl))
- pedwarn ("%q+D is static but declared in inline function %qD "
- "which is not static", decl, current_function_decl);
+ pedwarn (0, "%q+D is static but declared in inline function %qD "
+ "which is not static", decl, current_function_decl);
/* Add this decl to the current scope.
TEM may equal DECL or it may be a previous decl of the same name. */
tem = pushdecl (decl);
@@ -3692,11 +3693,11 @@ mark_forward_parm_decls (void)
{
struct c_binding *b;
if (pedantic && !current_scope->warned_forward_parm_decls)
{
- pedwarn ("ISO C forbids forward parameter declarations");
+ pedwarn (OPT_pedantic, "ISO C forbids forward parameter declarations");
current_scope->warned_forward_parm_decls = true;
}
for (b = current_scope->bindings; b; b = b->prev)
if (TREE_CODE (b->decl) == PARM_DECL)
@@ -3839,16 +3840,15 @@ check_bitfield_type_and_width (tree *typ
error ("bit-field %qs has invalid type", name);
*type = unsigned_type_node;
}
type_mv = TYPE_MAIN_VARIANT (*type);
- if (pedantic
- && !in_system_header
+ if (!in_system_header
&& type_mv != integer_type_node
&& type_mv != unsigned_type_node
&& type_mv != boolean_type_node)
- pedwarn ("type of bit-field %qs is a GCC extension", name);
+ pedwarn (OPT_pedantic, "type of bit-field %qs is a GCC extension", name);
max_width = TYPE_PRECISION (*type);
if (0 < compare_tree_int (*width, max_width))
{
@@ -3874,32 +3874,31 @@ check_bitfield_type_and_width (tree *typ
/* Print warning about variable length array if necessary. */
static void
warn_variable_length_array (const char *name, tree size)
{
- int ped = !flag_isoc99 && pedantic && warn_vla != 0;
int const_size = TREE_CONSTANT (size);
- if (ped)
+ if (!flag_isoc99 && pedantic && warn_vla != 0)
{
if (const_size)
{
if (name)
- pedwarn ("ISO C90 forbids array %qs whose size "
+ pedwarn (OPT_Wvla, "ISO C90 forbids array %qs whose size "
"can%'t be evaluated",
name);
else
- pedwarn ("ISO C90 forbids array whose size "
+ pedwarn (OPT_Wvla, "ISO C90 forbids array whose size "
"can%'t be evaluated");
}
else
{
if (name)
- pedwarn ("ISO C90 forbids variable length array %qs",
+ pedwarn (OPT_Wvla, "ISO C90 forbids variable length array %qs",
name);
else
- pedwarn ("ISO C90 forbids variable length array");
+ pedwarn (OPT_Wvla, "ISO C90 forbids variable length array");
}
}
else if (warn_vla > 0)
{
if (const_size)
@@ -4056,12 +4055,13 @@ grokdeclarator (const struct c_declarato
-Wreturn-type and this is a function, or if -Wimplicit;
prefer the former warning since it is more explicit. */
if ((warn_implicit_int || warn_return_type || flag_isoc99)
&& funcdef_flag)
warn_about_return_type = 1;
- else if (warn_implicit_int || flag_isoc99)
- pedwarn_c99 ("type defaults to %<int%> in declaration of %qs", name);
+ else
+ pedwarn_c99 (flag_isoc99 ? 0 : OPT_Wimplicit_int,
+ "type defaults to %<int%> in declaration of %qs", name);
}
/* Adjust the type if a bit-field is being declared,
-funsigned-bitfields applied and the type is not explicitly
"signed". */
@@ -4085,15 +4085,15 @@ grokdeclarator (const struct c_declarato
restrictp = declspecs->restrict_p + TYPE_RESTRICT (element_type);
volatilep = declspecs->volatile_p + TYPE_VOLATILE (element_type);
if (pedantic && !flag_isoc99)
{
if (constp > 1)
- pedwarn ("duplicate %<const%>");
+ pedwarn (OPT_pedantic, "duplicate %<const%>");
if (restrictp > 1)
- pedwarn ("duplicate %<restrict%>");
+ pedwarn (OPT_pedantic, "duplicate %<restrict%>");
if (volatilep > 1)
- pedwarn ("duplicate %<volatile%>");
+ pedwarn (OPT_pedantic, "duplicate %<volatile%>");
}
if (!flag_gen_aux_info && (TYPE_QUALS (element_type)))
type = TYPE_MAIN_VARIANT (type);
type_quals = ((constp ? TYPE_QUAL_CONST : 0)
| (restrictp ? TYPE_QUAL_RESTRICT : 0)
@@ -4106,13 +4106,13 @@ grokdeclarator (const struct c_declarato
&& (threadp
|| storage_class == csc_auto
|| storage_class == csc_register
|| storage_class == csc_typedef))
{
- if (storage_class == csc_auto
- && (pedantic || current_scope == file_scope))
- pedwarn ("function definition declared %<auto%>");
+ if (storage_class == csc_auto)
+ pedwarn ((current_scope == file_scope) ? 0 : OPT_pedantic,
+ "function definition declared %<auto%>");
if (storage_class == csc_register)
error ("function definition declared %<register%>");
if (storage_class == csc_typedef)
error ("function definition declared %<typedef%>");
if (threadp)
@@ -4164,11 +4164,11 @@ grokdeclarator (const struct c_declarato
else if (current_scope == file_scope)
{
if (storage_class == csc_auto)
error ("file-scope declaration of %qs specifies %<auto%>", name);
if (pedantic && storage_class == csc_register)
- pedwarn ("file-scope declaration of %qs specifies %<register%>", name);
+ pedwarn (OPT_pedantic, "file-scope declaration of %qs specifies %<register%>", name);
}
else
{
if (storage_class == csc_extern && funcdef_flag)
error ("nested function %qs declared %<extern%>", name);
@@ -4277,11 +4277,11 @@ grokdeclarator (const struct c_declarato
error ("declaration of %qs as array of functions", name);
type = error_mark_node;
}
if (pedantic && !in_system_header && flexible_array_type_p (type))
- pedwarn ("invalid use of structure with flexible array member");
+ pedwarn (OPT_pedantic, "invalid use of structure with flexible array member");
if (size == error_mark_node)
type = error_mark_node;
if (type == error_mark_node)
@@ -4302,11 +4302,11 @@ grokdeclarator (const struct c_declarato
error ("size of array %qs has non-integer type", name);
size = integer_one_node;
}
if (pedantic && integer_zerop (size))
- pedwarn ("ISO C forbids zero-size array %qs", name);
+ pedwarn (OPT_pedantic, "ISO C forbids zero-size array %qs", name);
if (TREE_CODE (size) == INTEGER_CST)
{
constant_expression_warning (size);
if (tree_int_cst_sgn (size) < 0)
@@ -4374,11 +4374,11 @@ grokdeclarator (const struct c_declarato
}
}
else if (decl_context == FIELD)
{
if (pedantic && !flag_isoc99 && !in_system_header)
- pedwarn ("ISO C90 does not support flexible array members");
+ pedwarn (OPT_pedantic, "ISO C90 does not support flexible array members");
/* ISO C99 Flexible array members are effectively
identical to GCC's zero-length array extension. */
itype = build_range_type (sizetype, size_zero_node, NULL_TREE);
}
@@ -4519,11 +4519,11 @@ grokdeclarator (const struct c_declarato
effect, so give a warning at -Wreturn-type.
Qualifiers on a void return type are banned on
function definitions in ISO C; GCC used to used
them for noreturn functions. */
if (VOID_TYPE_P (type) && really_funcdef)
- pedwarn ("function definition has qualified void return type");
+ pedwarn (0, "function definition has qualified void return type");
else
warning (OPT_Wignored_qualifiers,
"type qualifiers ignored on function return type");
type = c_build_qualified_type (type, type_quals);
@@ -4551,11 +4551,11 @@ grokdeclarator (const struct c_declarato
/* Merge any constancy or volatility into the target type
for the pointer. */
if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
&& type_quals)
- pedwarn ("ISO C forbids qualified function types");
+ pedwarn (OPT_pedantic, "ISO C forbids qualified function types");
if (type_quals)
type = c_build_qualified_type (type, type_quals);
size_varies = 0;
/* When the pointed-to type involves components of variable size,
@@ -4632,19 +4632,19 @@ grokdeclarator (const struct c_declarato
if (storage_class == csc_typedef)
{
tree decl;
if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
&& type_quals)
- pedwarn ("ISO C forbids qualified function types");
+ pedwarn (OPT_pedantic, "ISO C forbids qualified function types");
if (type_quals)
type = c_build_qualified_type (type, type_quals);
decl = build_decl (TYPE_DECL, declarator->u.id, type);
DECL_SOURCE_LOCATION (decl) = declarator->id_loc;
if (declspecs->explicit_signed_p)
C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1;
if (declspecs->inline_p)
- pedwarn ("typedef %q+D declared %<inline%>", decl);
+ pedwarn (0, "typedef %q+D declared %<inline%>", decl);
return decl;
}
/* If this is a type name (such as, in a cast or sizeof),
compute the type and return it now. */
@@ -4655,21 +4655,22 @@ grokdeclarator (const struct c_declarato
and fields. */
gcc_assert (storage_class == csc_none && !threadp
&& !declspecs->inline_p);
if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
&& type_quals)
- pedwarn ("ISO C forbids const or volatile function types");
+ pedwarn (OPT_pedantic, "ISO C forbids const or volatile function types");
if (type_quals)
type = c_build_qualified_type (type, type_quals);
return type;
}
if (pedantic && decl_context == FIELD
&& variably_modified_type_p (type, NULL_TREE))
{
/* C99 6.7.2.1p8 */
- pedwarn ("a member of a structure or union cannot have a variably modified type");
+ pedwarn (OPT_pedantic,
+ "a member of a structure or union cannot have a variably modified type");
}
/* Aside from typedefs and type names (handle above),
`void' at top level (not within pointer)
is allowed only in public variables.
@@ -4718,12 +4719,12 @@ grokdeclarator (const struct c_declarato
size_varies = 0;
}
else if (TREE_CODE (type) == FUNCTION_TYPE)
{
- if (pedantic && type_quals)
- pedwarn ("ISO C forbids qualified function types");
+ if (type_quals)
+ pedwarn (OPT_pedantic, "ISO C forbids qualified function types");
if (type_quals)
type = c_build_qualified_type (type, type_quals);
type = build_pointer_type (type);
type_quals = TYPE_UNQUALIFIED;
}
@@ -4745,11 +4746,11 @@ grokdeclarator (const struct c_declarato
else
promoted_type = c_type_promotes_to (type);
DECL_ARG_TYPE (decl) = promoted_type;
if (declspecs->inline_p)
- pedwarn ("parameter %q+D declared %<inline%>", decl);
+ pedwarn (0, "parameter %q+D declared %<inline%>", decl);
}
else if (decl_context == FIELD)
{
/* Note that the grammar rejects storage classes in typenames
and fields. */
@@ -4791,14 +4792,11 @@ grokdeclarator (const struct c_declarato
classes other than `extern' are not allowed, C99
6.7.1p5, and `extern' makes no difference. However,
GCC allows 'auto', perhaps with 'inline', to support
nested functions. */
if (storage_class == csc_auto)
- {
- if (pedantic)
- pedwarn ("invalid storage class for function %qs", name);
- }
+ pedwarn (OPT_pedantic, "invalid storage class for function %qs", name);
else if (storage_class == csc_static)
{
error ("invalid storage class for function %qs", name);
if (funcdef_flag)
storage_class = declspecs->storage_class = csc_none;
@@ -4810,11 +4808,12 @@ grokdeclarator (const struct c_declarato
decl = build_decl (FUNCTION_DECL, declarator->u.id, type);
DECL_SOURCE_LOCATION (decl) = declarator->id_loc;
decl = build_decl_attribute_variant (decl, decl_attr);
if (pedantic && type_quals && !DECL_IN_SYSTEM_HEADER (decl))
- pedwarn ("ISO C forbids qualified function types");
+ pedwarn (OPT_pedantic,
+ "ISO C forbids qualified function types");
/* GNU C interprets a volatile-qualified function type to indicate
that the function does not return. */
if ((type_quals & TYPE_QUAL_VOLATILE)
&& !VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl))))
@@ -4852,11 +4851,11 @@ grokdeclarator (const struct c_declarato
/* Record presence of `inline', if it is reasonable. */
if (flag_hosted && MAIN_NAME_P (declarator->u.id))
{
if (declspecs->inline_p)
- pedwarn ("cannot inline function %<main%>");
+ pedwarn (0, "cannot inline function %<main%>");
}
else if (declspecs->inline_p)
{
/* Record that the function is declared `inline'. */
DECL_DECLARED_INLINE_P (decl) = 1;
@@ -4905,11 +4904,11 @@ grokdeclarator (const struct c_declarato
DECL_SOURCE_LOCATION (decl) = declarator->id_loc;
if (size_varies)
C_DECL_VARIABLE_SIZE (decl) = 1;
if (declspecs->inline_p)
- pedwarn ("variable %q+D declared %<inline%>", decl);
+ pedwarn (0, "variable %q+D declared %<inline%>", decl);
/* At file scope, an initialized extern declaration may follow
a static declaration. In that case, DECL_EXTERNAL will be
reset later in start_decl. */
DECL_EXTERNAL (decl) = (storage_class == csc_extern);
@@ -5013,11 +5012,11 @@ grokparms (struct c_arg_info *arg_info,
return 0; /* don't set TYPE_ARG_TYPES in this case */
else if (arg_types && TREE_CODE (TREE_VALUE (arg_types)) == IDENTIFIER_NODE)
{
if (!funcdef_flag)
- pedwarn ("parameter names (without types) in function declaration");
+ pedwarn (0, "parameter names (without types) in function declaration");
arg_info->parms = arg_info->types;
arg_info->types = 0;
return 0;
}
@@ -5427,15 +5426,14 @@ grokfield (struct c_declarator *declarat
else
ok = false;
}
if (!ok)
{
- pedwarn ("declaration does not declare anything");
+ pedwarn (0, "declaration does not declare anything");
return NULL_TREE;
}
- if (pedantic)
- pedwarn ("ISO C doesn%'t support unnamed structs/unions");
+ pedwarn (OPT_pedantic, "ISO C doesn%'t support unnamed structs/unions");
}
value = grokdeclarator (declarator, declspecs, FIELD, false,
width ? &width : NULL, decl_attrs,
DEPRECATED_NORMAL);
@@ -5530,20 +5528,20 @@ finish_struct (tree t, tree fieldlist, t
if (x == 0)
{
if (TREE_CODE (t) == UNION_TYPE)
{
if (fieldlist)
- pedwarn ("union has no named members");
+ pedwarn (OPT_pedantic, "union has no named members");
else
- pedwarn ("union has no members");
+ pedwarn (OPT_pedantic, "union has no members");
}
else
{
if (fieldlist)
- pedwarn ("struct has no named members");
+ pedwarn (OPT_pedantic, "struct has no named members");
else
- pedwarn ("struct has no members");
+ pedwarn (OPT_pedantic, "struct has no members");
}
}
}
/* Install struct as DECL_CONTEXT of each field decl.
@@ -5618,11 +5616,12 @@ finish_struct (tree t, tree fieldlist, t
}
}
if (pedantic && !in_system_header && TREE_CODE (t) == RECORD_TYPE
&& flexible_array_type_p (TREE_TYPE (x)))
- pedwarn ("%Jinvalid use of structure with flexible array member", x);
+ pedwarn (OPT_pedantic,
+ "%Jinvalid use of structure with flexible array member", x);
if (DECL_NAME (x))
saw_named_field = 1;
}
@@ -6003,11 +6002,11 @@ build_enumerator (struct c_enum_contents
error ("overflow in enumeration values");
}
if (pedantic && !int_fits_type_p (value, integer_type_node))
{
- pedwarn ("ISO C restricts enumerator values to range of %<int%>");
+ pedwarn (OPT_pedantic, "ISO C restricts enumerator values to range of %<int%>");
/* XXX This causes -pedantic to change the meaning of the program.
Remove? -zw 2004-03-15 */
value = convert (integer_type_node, value);
}
@@ -6119,11 +6118,13 @@ start_function (struct c_declspecs *decl
= build_function_type (void_type_node,
TYPE_ARG_TYPES (TREE_TYPE (decl1)));
}
if (warn_about_return_type)
- pedwarn_c99 ("return type defaults to %<int%>");
+ pedwarn_c99 (flag_isoc99 ? 0
+ : (warn_return_type ? OPT_Wreturn_type : OPT_Wimplicit_int),
+ "return type defaults to %<int%>");
/* Make the init_value nonzero so pushdecl knows this is not tentative.
error_mark_node is replaced below (in pop_scope) with the BLOCK. */
DECL_INITIAL (decl1) = error_mark_node;
@@ -6240,16 +6241,16 @@ start_function (struct c_declspecs *decl
/* Warn for unlikely, improbable, or stupid declarations of `main'. */
if (warn_main > 0 && MAIN_NAME_P (DECL_NAME (decl1)))
{
if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (decl1)))
!= integer_type_node)
- pedwarn ("return type of %q+D is not %<int%>", decl1);
+ pedwarn (OPT_Wmain, "return type of %q+D is not %<int%>", decl1);
check_main_parameter_types(decl1);
if (!TREE_PUBLIC (decl1))
- pedwarn ("%q+D is normally a non-static function", decl1);
+ pedwarn (OPT_Wmain, "%q+D is normally a non-static function", decl1);
}
/* Record the decl so that the function name is defined.
If we already have a decl for this name, and it is a FUNCTION_DECL,
use the old decl. */
@@ -6393,11 +6394,11 @@ store_parm_decls_oldstyle (tree fndecl,
DECL_SOURCE_LOCATION (decl) = DECL_SOURCE_LOCATION (fndecl);
pushdecl (decl);
warn_if_shadowing (decl);
if (flag_isoc99)
- pedwarn ("type of %q+D defaults to %<int%>", decl);
+ pedwarn (0, "type of %q+D defaults to %<int%>", decl);
else
warning (OPT_Wmissing_parameter_type, "type of %q+D defaults to %<int%>", decl);
}
TREE_PURPOSE (parm) = decl;
@@ -6504,26 +6505,23 @@ store_parm_decls_oldstyle (tree fndecl,
&& INTEGRAL_TYPE_P (TREE_TYPE (parm))
&& TYPE_PRECISION (TREE_TYPE (parm))
< TYPE_PRECISION (integer_type_node))
DECL_ARG_TYPE (parm) = integer_type_node;
- if (pedantic)
+ /* ??? Is it possible to get here with a
+ built-in prototype or will it always have
+ been diagnosed as conflicting with an
+ old-style definition and discarded? */
+ if (current_function_prototype_built_in)
+ warning (OPT_pedantic, "promoted argument %qD "
+ "doesn%'t match built-in prototype", parm);
+ else
{
- /* ??? Is it possible to get here with a
- built-in prototype or will it always have
- been diagnosed as conflicting with an
- old-style definition and discarded? */
- if (current_function_prototype_built_in)
- warning (0, "promoted argument %qD "
- "doesn%'t match built-in prototype", parm);
- else
- {
- pedwarn ("promoted argument %qD "
- "doesn%'t match prototype", parm);
- pedwarn ("%Hprototype declaration",
- ¤t_function_prototype_locus);
- }
+ pedwarn (OPT_pedantic, "promoted argument %qD "
+ "doesn%'t match prototype", parm);
+ pedwarn (OPT_pedantic, "%Hprototype declaration",
+ ¤t_function_prototype_locus);
}
}
else
{
if (current_function_prototype_built_in)
@@ -6711,11 +6709,11 @@ finish_function (void)
!= integer_type_node)
{
/* If warn_main is 1 (-Wmain) or 2 (-Wall), we have already warned.
If warn_main is -1 (-Wno-main) we don't want to be warned. */
if (!warn_main)
- pedwarn ("return type of %q+D is not %<int%>", fndecl);
+ pedwarn (0, "return type of %q+D is not %<int%>", fndecl);
}
else
{
if (flag_isoc99)
{
@@ -7162,12 +7160,12 @@ declspecs_add_qual (struct c_declspecs *
specs->restrict_p = true;
break;
default:
gcc_unreachable ();
}
- if (dupe && pedantic && !flag_isoc99)
- pedwarn ("duplicate %qE", qual);
+ if (dupe && !flag_isoc99)
+ pedwarn (OPT_pedantic, "duplicate %qE", qual);
return specs;
}
/* Add the type specifier TYPE to the declaration specifiers SPECS,
returning SPECS. */
@@ -7211,13 +7209,12 @@ declspecs_add_type (struct c_declspecs *
{
error ("both %<long long%> and %<double%> in "
"declaration specifiers");
break;
}
- if (pedantic && !flag_isoc99 && !in_system_header
- && warn_long_long)
- pedwarn ("ISO C90 does not support %<long long%>");
+ if (pedantic && !flag_isoc99 && !in_system_header)
+ pedwarn (OPT_Wlong_long, "ISO C90 does not support %<long long%>");
specs->long_long_p = 1;
break;
}
if (specs->short_p)
error ("both %<long%> and %<short%> in "
@@ -7336,12 +7333,12 @@ declspecs_add_type (struct c_declspecs *
else
specs->unsigned_p = true;
break;
case RID_COMPLEX:
dupe = specs->complex_p;
- if (pedantic && !flag_isoc99 && !in_system_header)
- pedwarn ("ISO C90 does not support complex types");
+ if (!flag_isoc99 && !in_system_header)
+ pedwarn (OPT_pedantic, "ISO C90 does not support complex types");
if (specs->typespec_word == cts_void)
error ("both %<complex%> and %<void%> in "
"declaration specifiers");
else if (specs->typespec_word == cts_bool)
error ("both %<complex%> and %<_Bool%> in "
@@ -7367,12 +7364,11 @@ declspecs_add_type (struct c_declspecs *
else
specs->complex_p = true;
break;
case RID_SAT:
dupe = specs->saturating_p;
- if (pedantic)
- pedwarn ("ISO C does not support saturating types");
+ pedwarn (OPT_pedantic, "ISO C does not support saturating types");
if (specs->typespec_word == cts_void)
error ("both %<_Sat%> and %<void%> in "
"declaration specifiers");
else if (specs->typespec_word == cts_bool)
error ("both %<_Sat%> and %<_Bool%> in "
@@ -7565,12 +7561,12 @@ declspecs_add_type (struct c_declspecs *
else
specs->typespec_word = cts_dfloat128;
}
if (!targetm.decimal_float_supported_p ())
error ("decimal floating point not supported for this target");
- if (pedantic)
- pedwarn ("ISO C does not support decimal floating point");
+ pedwarn (OPT_pedantic,
+ "ISO C does not support decimal floating point");
return specs;
case RID_FRACT:
case RID_ACCUM:
{
const char *str;
@@ -7586,12 +7582,12 @@ declspecs_add_type (struct c_declspecs *
else
specs->typespec_word = cts_accum;
}
if (!targetm.fixed_point_supported_p ())
error ("fixed-point types not supported for this target");
- if (pedantic)
- pedwarn ("ISO C does not support fixed-point types");
+ pedwarn (OPT_pedantic,
+ "ISO C does not support fixed-point types");
return specs;
default:
/* ObjC reserved word "id", handled below. */
break;
}
@@ -7773,13 +7769,13 @@ finish_declspecs (struct c_declspecs *sp
specs->typespec_word = cts_int;
}
else if (specs->complex_p)
{
specs->typespec_word = cts_double;
- if (pedantic)
- pedwarn ("ISO C does not support plain %<complex%> meaning "
- "%<double complex%>");
+ pedwarn (OPT_pedantic,
+ "ISO C does not support plain %<complex%> meaning "
+ "%<double complex%>");
}
else
{
specs->typespec_word = cts_int;
specs->default_int_p = true;
@@ -7818,12 +7814,12 @@ finish_declspecs (struct c_declspecs *sp
specs->type = unsigned_char_type_node;
else
specs->type = char_type_node;
if (specs->complex_p)
{
- if (pedantic)
- pedwarn ("ISO C does not support complex integer types");
+ pedwarn (OPT_pedantic,
+ "ISO C does not support complex integer types");
specs->type = build_complex_type (specs->type);
}
break;
case cts_int:
gcc_assert (!(specs->long_p && specs->short_p));
@@ -7844,12 +7840,12 @@ finish_declspecs (struct c_declspecs *sp
specs->type = (specs->unsigned_p
? unsigned_type_node
: integer_type_node);
if (specs->complex_p)
{
- if (pedantic)
- pedwarn ("ISO C does not support complex integer types");
+ pedwarn (OPT_pedantic,
+ "ISO C does not support complex integer types");
specs->type = build_complex_type (specs->type);
}
break;
case cts_float:
gcc_assert (!specs->long_p && !specs->short_p
@@ -7995,11 +7991,11 @@ c_write_global_declarations_1 (tree glob
&& DECL_INITIAL (decl) == 0
&& DECL_EXTERNAL (decl)
&& !TREE_PUBLIC (decl)
&& C_DECL_USED (decl))
{
- pedwarn ("%q+F used but never defined", decl);
+ pedwarn (0, "%q+F used but never defined", decl);
TREE_NO_WARNING (decl) = 1;
}
wrapup_global_declaration_1 (decl);
}
Index: gcc/c-typeck.c
===================================================================
--- gcc/c-typeck.c (revision 138044)
+++ gcc/c-typeck.c (working copy)
@@ -468,12 +468,12 @@ composite_type (tree t1, tree t2)
mv3 = TYPE_MAIN_VARIANT (mv3);
if (comptypes (mv3, mv2))
{
TREE_VALUE (n) = composite_type (TREE_TYPE (memb),
TREE_VALUE (p2));
- if (pedantic)
- pedwarn ("function types not truly compatible in ISO C");
+ pedwarn (OPT_pedantic,
+ "function types not truly compatible in ISO C");
goto parm_done;
}
}
}
if (TREE_CODE (TREE_VALUE (p2)) == UNION_TYPE
@@ -493,12 +493,12 @@ composite_type (tree t1, tree t2)
mv3 = TYPE_MAIN_VARIANT (mv3);
if (comptypes (mv3, mv1))
{
TREE_VALUE (n) = composite_type (TREE_TYPE (memb),
TREE_VALUE (p1));
- if (pedantic)
- pedwarn ("function types not truly compatible in ISO C");
+ pedwarn (OPT_pedantic,
+ "function types not truly compatible in ISO C");
goto parm_done;
}
}
}
TREE_VALUE (n) = composite_type (TREE_VALUE (p1), TREE_VALUE (p2));
@@ -1037,12 +1037,12 @@ comp_target_types (tree ttl, tree ttr)
mvl = TYPE_MAIN_VARIANT (mvl);
if (TREE_CODE (mvr) != ARRAY_TYPE)
mvr = TYPE_MAIN_VARIANT (mvr);
val = comptypes (mvl, mvr);
- if (val == 2 && pedantic)
- pedwarn ("types are not quite compatible");
+ if (val == 2)
+ pedwarn (OPT_pedantic, "types are not quite compatible");
return val;
}
/* Subroutines of `comptypes'. */
@@ -1361,11 +1361,11 @@ function_types_compatible_p (const_tree
ret2 = TREE_TYPE (f2);
/* 'volatile' qualifiers on a function's return type used to mean
the function is noreturn. */
if (TYPE_VOLATILE (ret1) != TYPE_VOLATILE (ret2))
- pedwarn ("function return types not compatible due to %<volatile%>");
+ pedwarn (0, "function return types not compatible due to %<volatile%>");
if (TYPE_VOLATILE (ret1))
ret1 = build_qualified_type (TYPE_MAIN_VARIANT (ret1),
TYPE_QUALS (ret1) & ~TYPE_QUAL_VOLATILE);
if (TYPE_VOLATILE (ret2))
ret2 = build_qualified_type (TYPE_MAIN_VARIANT (ret2),
@@ -2113,13 +2113,15 @@ build_array_ref (tree array, tree index)
{
tree foo = array;
while (TREE_CODE (foo) == COMPONENT_REF)
foo = TREE_OPERAND (foo, 0);
if (TREE_CODE (foo) == VAR_DECL && C_DECL_REGISTER (foo))
- pedwarn ("ISO C forbids subscripting %<register%> array");
+ pedwarn (OPT_pedantic,
+ "ISO C forbids subscripting %<register%> array");
else if (!flag_isoc99 && !lvalue_p (foo))
- pedwarn ("ISO C90 forbids subscripting non-lvalue array");
+ pedwarn (OPT_pedantic,
+ "ISO C90 forbids subscripting non-lvalue array");
}
type = TREE_TYPE (TREE_TYPE (array));
rval = build4 (ARRAY_REF, type, array, index, NULL_TREE, NULL_TREE);
/* Array ref is const/volatile if the array elements are
@@ -2231,12 +2233,12 @@ build_external_ref (tree id, int fun, lo
&& DECL_EXTERNAL (current_function_decl)
&& VAR_OR_FUNCTION_DECL_P (ref)
&& (TREE_CODE (ref) != VAR_DECL || TREE_STATIC (ref))
&& ! TREE_PUBLIC (ref)
&& DECL_CONTEXT (ref) != current_function_decl)
- pedwarn ("%H%qD is static but used in inline function %qD "
- "which is not static", &loc, ref, current_function_decl);
+ pedwarn (0, "%H%qD is static but used in inline function %qD "
+ "which is not static", &loc, ref, current_function_decl);
return ref;
}
/* Record details of decls possibly used inside sizeof or typeof. */
@@ -2456,11 +2458,11 @@ build_function_call (tree function, tree
result = fold_build_call_array_initializer (TREE_TYPE (fntype),
function, nargs, argarray);
if (TREE_CONSTANT (result)
&& (name == NULL_TREE
|| strncmp (IDENTIFIER_POINTER (name), "__builtin_", 10) != 0))
- pedwarn_init ("initializer element is not constant");
+ pedwarn_init (0, "initializer element is not constant");
}
else
result = fold_build_call_array (TREE_TYPE (fntype),
function, nargs, argarray);
@@ -2800,17 +2802,16 @@ pointer_diff (tree op0, tree op1)
tree target_type = TREE_TYPE (TREE_TYPE (op0));
tree con0, con1, lit0, lit1;
tree orig_op1 = op1;
- if (pedantic || warn_pointer_arith)
- {
- if (TREE_CODE (target_type) == VOID_TYPE)
- pedwarn ("pointer of type %<void *%> used in subtraction");
- if (TREE_CODE (target_type) == FUNCTION_TYPE)
- pedwarn ("pointer to a function used in subtraction");
- }
+ if (TREE_CODE (target_type) == VOID_TYPE)
+ pedwarn (pedantic ? OPT_pedantic : OPT_Wpointer_arith,
+ "pointer of type %<void *%> used in subtraction");
+ if (TREE_CODE (target_type) == FUNCTION_TYPE)
+ pedwarn (pedantic ? OPT_pedantic : OPT_Wpointer_arith,
+ "pointer to a function used in subtraction");
/* If the conversion to ptrdiff_type does anything like widening or
converting a partial to an integral mode, we get a convert_expression
that is in the way to do any simplifications.
(fold-const.c doesn't know that the extra bits won't be needed.
@@ -2948,12 +2949,12 @@ build_unary_op (enum tree_code code, tre
arg = default_conversion (arg);
}
else if (typecode == COMPLEX_TYPE)
{
code = CONJ_EXPR;
- if (pedantic)
- pedwarn ("ISO C does not support %<~%> for complex conjugation");
+ pedwarn (OPT_pedantic,
+ "ISO C does not support %<~%> for complex conjugation");
if (!noconvert)
arg = default_conversion (arg);
}
else
{
@@ -3020,13 +3021,12 @@ build_unary_op (enum tree_code code, tre
and don't change the imaginary part. */
if (typecode == COMPLEX_TYPE)
{
tree real, imag;
- if (pedantic)
- pedwarn ("ISO C does not support %<++%> and %<--%>"
- " on complex types");
+ pedwarn (OPT_pedantic, "ISO C does not support %<++%> and %<--%>"
+ " on complex types");
arg = stabilize_reference (arg);
real = build_unary_op (REALPART_EXPR, arg, 1);
imag = build_unary_op (IMAGPART_EXPR, arg, 1);
real = build_unary_op (code, real, 1);
@@ -3067,18 +3067,19 @@ build_unary_op (enum tree_code code, tre
if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
error ("increment of pointer to unknown structure");
else
error ("decrement of pointer to unknown structure");
}
- else if ((pedantic || warn_pointer_arith)
- && (TREE_CODE (TREE_TYPE (result_type)) == FUNCTION_TYPE
- || TREE_CODE (TREE_TYPE (result_type)) == VOID_TYPE))
+ else if (TREE_CODE (TREE_TYPE (result_type)) == FUNCTION_TYPE
+ || TREE_CODE (TREE_TYPE (result_type)) == VOID_TYPE)
{
if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
- pedwarn ("wrong type argument to increment");
+ pedwarn (pedantic ? OPT_pedantic : OPT_Wpointer_arith,
+ "wrong type argument to increment");
else
- pedwarn ("wrong type argument to decrement");
+ pedwarn (pedantic ? OPT_pedantic : OPT_Wpointer_arith,
+ "wrong type argument to decrement");
}
inc = c_size_in_bytes (TREE_TYPE (result_type));
inc = fold_convert (sizetype, inc);
}
@@ -3349,11 +3350,11 @@ c_mark_addressable (tree exp)
{
error
("global register variable %qD used in nested function", x);
return false;
}
- pedwarn ("register variable %qD used in nested function", x);
+ pedwarn (0, "register variable %qD used in nested function", x);
}
else if (C_DECL_REGISTER (x))
{
if (TREE_PUBLIC (x) || TREE_STATIC (x) || DECL_EXTERNAL (x))
error ("address of global register variable %qD requested", x);
@@ -3456,12 +3457,13 @@ build_conditional_expr (tree ifexp, tree
}
}
}
else if (code1 == VOID_TYPE || code2 == VOID_TYPE)
{
- if (pedantic && (code1 != VOID_TYPE || code2 != VOID_TYPE))
- pedwarn ("ISO C forbids conditional expr with only one void side");
+ if (code1 != VOID_TYPE || code2 != VOID_TYPE)
+ pedwarn (OPT_pedantic,
+ "ISO C forbids conditional expr with only one void side");
result_type = void_type_node;
}
else if (code1 == POINTER_TYPE && code2 == POINTER_TYPE)
{
if (comp_target_types (type1, type2))
@@ -3470,44 +3472,44 @@ build_conditional_expr (tree ifexp, tree
result_type = qualify_type (type2, type1);
else if (null_pointer_constant_p (orig_op2))
result_type = qualify_type (type1, type2);
else if (VOID_TYPE_P (TREE_TYPE (type1)))
{
- if (pedantic && TREE_CODE (TREE_TYPE (type2)) == FUNCTION_TYPE)
- pedwarn ("ISO C forbids conditional expr between "
+ if (TREE_CODE (TREE_TYPE (type2)) == FUNCTION_TYPE)
+ pedwarn (OPT_pedantic, "ISO C forbids conditional expr between "
"%<void *%> and function pointer");
result_type = build_pointer_type (qualify_type (TREE_TYPE (type1),
TREE_TYPE (type2)));
}
else if (VOID_TYPE_P (TREE_TYPE (type2)))
{
- if (pedantic && TREE_CODE (TREE_TYPE (type1)) == FUNCTION_TYPE)
- pedwarn ("ISO C forbids conditional expr between "
+ if (TREE_CODE (TREE_TYPE (type1)) == FUNCTION_TYPE)
+ pedwarn (OPT_pedantic, "ISO C forbids conditional expr between "
"%<void *%> and function pointer");
result_type = build_pointer_type (qualify_type (TREE_TYPE (type2),
TREE_TYPE (type1)));
}
else
{
- pedwarn ("pointer type mismatch in conditional expression");
+ pedwarn (0, "pointer type mismatch in conditional expression");
result_type = build_pointer_type (void_type_node);
}
}
else if (code1 == POINTER_TYPE && code2 == INTEGER_TYPE)
{
if (!null_pointer_constant_p (orig_op2))
- pedwarn ("pointer/integer type mismatch in conditional expression");
+ pedwarn (0, "pointer/integer type mismatch in conditional expression");
else
{
op2 = null_pointer_node;
}
result_type = type1;
}
else if (code2 == POINTER_TYPE && code1 == INTEGER_TYPE)
{
if (!null_pointer_constant_p (orig_op1))
- pedwarn ("pointer/integer type mismatch in conditional expression");
+ pedwarn (0, "pointer/integer type mismatch in conditional expression");
else
{
op1 = null_pointer_node;
}
result_type = type2;
@@ -3614,16 +3616,14 @@ build_c_cast (tree type, tree expr)
return error_mark_node;
}
if (type == TYPE_MAIN_VARIANT (TREE_TYPE (value)))
{
- if (pedantic)
- {
- if (TREE_CODE (type) == RECORD_TYPE
- || TREE_CODE (type) == UNION_TYPE)
- pedwarn ("ISO C forbids casting nonscalar to the same type");
- }
+ if (TREE_CODE (type) == RECORD_TYPE
+ || TREE_CODE (type) == UNION_TYPE)
+ pedwarn (OPT_pedantic,
+ "ISO C forbids casting nonscalar to the same type");
}
else if (TREE_CODE (type) == UNION_TYPE)
{
tree field;
@@ -3635,12 +3635,11 @@ build_c_cast (tree type, tree expr)
if (field)
{
tree t;
- if (pedantic)
- pedwarn ("ISO C forbids casts to union type");
+ pedwarn (OPT_pedantic, "ISO C forbids casts to union type");
t = digest_init (type,
build_constructor_single (type, field, value),
true, 0);
TREE_CONSTANT (t) = TREE_CONSTANT (value);
return t;
@@ -3747,19 +3746,21 @@ build_c_cast (tree type, tree expr)
if (pedantic
&& TREE_CODE (type) == POINTER_TYPE
&& TREE_CODE (otype) == POINTER_TYPE
&& TREE_CODE (TREE_TYPE (otype)) == FUNCTION_TYPE
&& TREE_CODE (TREE_TYPE (type)) != FUNCTION_TYPE)
- pedwarn ("ISO C forbids conversion of function pointer to object pointer type");
+ pedwarn (OPT_pedantic, "ISO C forbids "
+ "conversion of function pointer to object pointer type");
if (pedantic
&& TREE_CODE (type) == POINTER_TYPE
&& TREE_CODE (otype) == POINTER_TYPE
&& TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE
&& TREE_CODE (TREE_TYPE (otype)) != FUNCTION_TYPE
&& !null_pointer_constant_p (value))
- pedwarn ("ISO C forbids conversion of object pointer to function pointer type");
+ pedwarn (OPT_pedantic, "ISO C forbids "
+ "conversion of object pointer to function pointer type");
ovalue = value;
value = convert (type, value);
/* Ignore any integer overflow caused by the cast. */
@@ -3951,23 +3952,23 @@ convert_for_assignment (tree type, tree
#define WARN_FOR_ASSIGNMENT(AR, AS, IN, RE) \
do { \
switch (errtype) \
{ \
case ic_argpass: \
- pedwarn (AR, parmnum, rname); \
+ pedwarn (0, AR, parmnum, rname); \
break; \
case ic_argpass_nonproto: \
- warning (0, AR, parmnum, rname); \
+ warning (0, AR, parmnum, rname); \
break; \
case ic_assign: \
- pedwarn (AS); \
+ pedwarn (0, AS); \
break; \
case ic_init: \
- pedwarn (IN); \
+ pedwarn (0, IN); \
break; \
case ic_return: \
- pedwarn (RE); \
+ pedwarn (0, RE); \
break; \
default: \
gcc_unreachable (); \
} \
} while (0)
@@ -4170,12 +4171,13 @@ convert_for_assignment (tree type, tree
"pointer target type"));
memb = marginal_memb;
}
- if (pedantic && (!fundecl || !DECL_IN_SYSTEM_HEADER (fundecl)))
- pedwarn ("ISO C prohibits argument conversion to union type");
+ if (!fundecl || !DECL_IN_SYSTEM_HEADER (fundecl))
+ pedwarn (OPT_pedantic,
+ "ISO C prohibits argument conversion to union type");
rhs = fold_convert (TREE_TYPE (memb), rhs);
return build_constructor_single (type, memb, rhs);
}
}
@@ -4616,23 +4618,24 @@ error_init (const char *msgid)
ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
if (*ofwhat)
error ("(near initialization for %qs)", ofwhat);
}
-/* Issue a pedantic warning for a bad initializer component.
- MSGID identifies the message.
- The component name is taken from the spelling stack. */
+/* Issue a pedantic warning for a bad initializer component. OPT is
+ the option OPT_* (from options.h) controlling this warning or 0 if
+ it is unconditionally given. MSGID identifies the message. The
+ component name is taken from the spelling stack. */
void
-pedwarn_init (const char *msgid)
+pedwarn_init (int opt, const char *msgid)
{
char *ofwhat;
- pedwarn ("%s", _(msgid));
+ pedwarn (opt, "%s", _(msgid));
ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
if (*ofwhat)
- pedwarn ("(near initialization for %qs)", ofwhat);
+ pedwarn (opt, "(near initialization for %qs)", ofwhat);
}
/* Issue a warning for a bad initializer component.
OPT is the OPT_W* value corresponding to the warning option that
@@ -4659,11 +4662,12 @@ maybe_warn_string_init (tree type, struc
{
if (pedantic
&& TREE_CODE (type) == ARRAY_TYPE
&& TREE_CODE (expr.value) == STRING_CST
&& expr.original_code != STRING_CST)
- pedwarn_init ("array initialized from parenthesized string constant");
+ pedwarn_init (OPT_pedantic,
+ "array initialized from parenthesized string constant");
}
/* Digest the parser output INIT as an initializer for type TYPE.
Return a C expression of type TYPE to represent the initial value.
@@ -4752,11 +4756,11 @@ digest_init (tree type, tree init, bool
that is counted in the length of the constant. */
&& 0 > compare_tree_int (TYPE_SIZE_UNIT (type),
TREE_STRING_LENGTH (inside_init)
- (TYPE_PRECISION (typ1)
/ BITS_PER_UNIT)))
- pedwarn_init ("initializer-string for array of chars is too long");
+ pedwarn_init (0, "initializer-string for array of chars is too long");
return inside_init;
}
else if (INTEGRAL_TYPE_P (typ1))
{
@@ -4867,11 +4871,11 @@ digest_init (tree type, tree init, bool
= valid_compound_expr_initializer (inside_init,
TREE_TYPE (inside_init));
if (inside_init == error_mark_node)
error_init ("initializer element is not constant");
else
- pedwarn_init ("initializer element is not constant");
+ pedwarn_init (OPT_pedantic, "initializer element is not constant");
if (flag_pedantic_errors)
inside_init = error_mark_node;
}
else if (require_constant
&& !initializer_constant_valid_p (inside_init,
@@ -5540,12 +5544,12 @@ pop_init_level (int implicit)
{
gcc_assert (!TYPE_SIZE (constructor_type));
if (constructor_depth > 2)
error_init ("initialization of flexible array member in a nested context");
- else if (pedantic)
- pedwarn_init ("initialization of a flexible array member");
+ else
+ pedwarn_init (OPT_pedantic, "initialization of a flexible array member");
/* We have already issued an error message for the existence
of a flexible array member not at the end of the structure.
Discard the initializer so that we do not die later. */
if (TREE_CHAIN (constructor_fields) != NULL_TREE)
@@ -6278,11 +6282,11 @@ output_init_element (tree value, bool st
{
error_init ("initializer element is not constant");
value = error_mark_node;
}
else if (require_constant_elements)
- pedwarn ("initializer element is not computable at load time");
+ pedwarn (0, "initializer element is not computable at load time");
}
/* If this field is empty (and not at the end of structure),
don't do anything other than checking the initializer. */
if (field
@@ -6605,11 +6609,11 @@ process_init_element (struct c_expr valu
tree fieldtype;
enum tree_code fieldcode;
if (constructor_fields == 0)
{
- pedwarn_init ("excess elements in struct initializer");
+ pedwarn_init (0, "excess elements in struct initializer");
break;
}
fieldtype = TREE_TYPE (constructor_fields);
if (fieldtype != error_mark_node)
@@ -6688,11 +6692,11 @@ process_init_element (struct c_expr valu
tree fieldtype;
enum tree_code fieldcode;
if (constructor_fields == 0)
{
- pedwarn_init ("excess elements in union initializer");
+ pedwarn_init (0, "excess elements in union initializer");
break;
}
fieldtype = TREE_TYPE (constructor_fields);
if (fieldtype != error_mark_node)
@@ -6775,11 +6779,11 @@ process_init_element (struct c_expr valu
if (constructor_max_index != 0
&& (tree_int_cst_lt (constructor_max_index, constructor_index)
|| integer_all_onesp (constructor_max_index)))
{
- pedwarn_init ("excess elements in array initializer");
+ pedwarn_init (0, "excess elements in array initializer");
break;
}
/* Now output the actual element. */
if (value.value)
@@ -6805,11 +6809,11 @@ process_init_element (struct c_expr valu
/* Do a basic check of initializer size. Note that vectors
always have a fixed size derived from their type. */
if (tree_int_cst_lt (constructor_max_index, constructor_index))
{
- pedwarn_init ("excess elements in vector initializer");
+ pedwarn_init (0, "excess elements in vector initializer");
break;
}
/* Now output the actual element. */
if (value.value)
@@ -6829,11 +6833,11 @@ process_init_element (struct c_expr valu
/* Handle the sole element allowed in a braced initializer
for a scalar variable. */
else if (constructor_type != error_mark_node
&& constructor_fields == 0)
{
- pedwarn_init ("excess elements in scalar initializer");
+ pedwarn_init (0, "excess elements in scalar initializer");
break;
}
else
{
if (value.value)
@@ -7060,12 +7064,11 @@ c_finish_goto_label (tree label)
/* Generate a computed goto statement to EXPR. */
tree
c_finish_goto_ptr (tree expr)
{
- if (pedantic)
- pedwarn ("ISO C forbids %<goto *expr;%>");
+ pedwarn (OPT_pedantic, "ISO C forbids %<goto *expr;%>");
expr = convert (ptr_type_node, expr);
return add_stmt (build1 (GOTO_EXPR, void_type_node, expr));
}
/* Generate a C `return' statement. RETVAL is the expression for what
@@ -7084,22 +7087,24 @@ c_finish_return (tree retval)
{
current_function_returns_null = 1;
if ((warn_return_type || flag_isoc99)
&& valtype != 0 && TREE_CODE (valtype) != VOID_TYPE)
{
- pedwarn_c99 ("%<return%> with no value, in "
+ pedwarn_c99 (flag_isoc99 ? 0 : OPT_Wreturn_type,
+ "%<return%> with no value, in "
"function returning non-void");
no_warning = true;
}
}
else if (valtype == 0 || TREE_CODE (valtype) == VOID_TYPE)
{
current_function_returns_null = 1;
if (TREE_CODE (TREE_TYPE (retval)) != VOID_TYPE)
- pedwarn ("%<return%> with a value, in function returning void");
- else if (pedantic)
- pedwarn ("ISO C forbids %<return%> with expression, in function returning void");
+ pedwarn (0, "%<return%> with a value, in function returning void");
+ else
+ pedwarn (OPT_pedantic, "ISO C forbids "
+ "%<return%> with expression, in function returning void");
}
else
{
tree t = convert_for_assignment (valtype, retval, ic_return,
NULL_TREE, NULL_TREE, 0);
@@ -8165,24 +8170,24 @@ build_binary_op (enum tree_code code, tr
{
/* op0 != orig_op0 detects the case of something
whose value is 0 but which isn't a valid null ptr const. */
if (pedantic && !null_pointer_constant_p (orig_op0)
&& TREE_CODE (tt1) == FUNCTION_TYPE)
- pedwarn ("ISO C forbids comparison of %<void *%>"
- " with function pointer");
+ pedwarn (OPT_pedantic, "ISO C forbids "
+ "comparison of %<void *%> with function pointer");
}
else if (VOID_TYPE_P (tt1))
{
if (pedantic && !null_pointer_constant_p (orig_op1)
&& TREE_CODE (tt0) == FUNCTION_TYPE)
- pedwarn ("ISO C forbids comparison of %<void *%>"
- " with function pointer");
+ pedwarn (OPT_pedantic, "ISO C forbids "
+ "comparison of %<void *%> with function pointer");
}
else
/* Avoid warning about the volatile ObjC EH puts on decls. */
if (!objc_ok)
- pedwarn ("comparison of distinct pointer types lacks a cast");
+ pedwarn (0, "comparison of distinct pointer types lacks a cast");
if (result_type == NULL_TREE)
result_type = ptr_type_node;
}
else if (code0 == POINTER_TYPE && null_pointer_constant_p (orig_op1))
@@ -8202,16 +8207,16 @@ build_binary_op (enum tree_code code, tr
result_type = type1;
}
else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
{
result_type = type0;
- pedwarn ("comparison between pointer and integer");
+ pedwarn (0, "comparison between pointer and integer");
}
else if (code0 == INTEGER_TYPE && code1 == POINTER_TYPE)
{
result_type = type1;
- pedwarn ("comparison between pointer and integer");
+ pedwarn (0, "comparison between pointer and integer");
}
break;
case LE_EXPR:
case GE_EXPR:
@@ -8228,42 +8233,42 @@ build_binary_op (enum tree_code code, tr
if (comp_target_types (type0, type1))
{
result_type = common_pointer_type (type0, type1);
if (!COMPLETE_TYPE_P (TREE_TYPE (type0))
!= !COMPLETE_TYPE_P (TREE_TYPE (type1)))
- pedwarn ("comparison of complete and incomplete pointers");
- else if (pedantic
- && TREE_CODE (TREE_TYPE (type0)) == FUNCTION_TYPE)
- pedwarn ("ISO C forbids ordered comparisons of pointers to functions");
+ pedwarn (0, "comparison of complete and incomplete pointers");
+ else if (TREE_CODE (TREE_TYPE (type0)) == FUNCTION_TYPE)
+ pedwarn (OPT_pedantic, "ISO C forbids "
+ "ordered comparisons of pointers to functions");
}
else
{
result_type = ptr_type_node;
- pedwarn ("comparison of distinct pointer types lacks a cast");
+ pedwarn (0, "comparison of distinct pointer types lacks a cast");
}
}
else if (code0 == POINTER_TYPE && null_pointer_constant_p (orig_op1))
{
result_type = type0;
- if (pedantic || extra_warnings)
- pedwarn ("ordered comparison of pointer with integer zero");
+ pedwarn (OPT_pedantic,
+ "ordered comparison of pointer with integer zero");
}
else if (code1 == POINTER_TYPE && null_pointer_constant_p (orig_op0))
{
result_type = type1;
- if (pedantic)
- pedwarn ("ordered comparison of pointer with integer zero");
+ pedwarn (OPT_pedantic,
+ "ordered comparison of pointer with integer zero");
}
else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
{
result_type = type0;
- pedwarn ("comparison between pointer and integer");
+ pedwarn (0, "comparison between pointer and integer");
}
else if (code0 == INTEGER_TYPE && code1 == POINTER_TYPE)
{
result_type = type1;
- pedwarn ("comparison between pointer and integer");
+ pedwarn (0, "comparison between pointer and integer");
}
break;
default:
gcc_unreachable ();
Index: gcc/c-common.c
===================================================================
--- gcc/c-common.c (revision 138044)
+++ gcc/c-common.c (working copy)
@@ -1039,11 +1039,11 @@ fname_decl (unsigned int rid, tree id)
= tree_cons (decl, stmts, saved_function_name_decls);
*fname_vars[ix].decl = decl;
input_location = saved_location;
}
if (!ix && !current_function_decl)
- pedwarn ("%qD is not defined outside of function scope", decl);
+ pedwarn (0, "%qD is not defined outside of function scope", decl);
return decl;
}
/* Given a STRING_CST, give it a suitable array-of-chars data type. */
@@ -1088,11 +1088,12 @@ fix_string_type (tree value)
if (nchars - 1 > nchars_max)
/* Translators: The %d after 'ISO C' will be 90 or 99. Do not
separate the %d from the 'C'. 'ISO' should not be
translated, but it may be moved after 'C%d' in languages
where modifiers follow nouns. */
- pedwarn ("string length %qd is greater than the length %qd "
+ pedwarn (OPT_Woverlength_strings,
+ "string length %qd is greater than the length %qd "
"ISO C%d compilers are required to support",
nchars - 1, nchars_max, relevant_std);
}
/* Create the array type for the string constant. The ISO C++
@@ -1135,11 +1136,11 @@ constant_expression_warning (tree value)
&& (TREE_CODE (value) == INTEGER_CST || TREE_CODE (value) == REAL_CST
|| TREE_CODE (value) == FIXED_CST
|| TREE_CODE (value) == VECTOR_CST
|| TREE_CODE (value) == COMPLEX_CST)
&& TREE_OVERFLOW (value))
- pedwarn ("overflow in constant expression");
+ pedwarn (OPT_Woverflow, "overflow in constant expression");
}
/* The same as above but print an unconditional error. */
void
constant_expression_error (tree value)
@@ -1353,38 +1354,38 @@ check_main_parameter_types (tree decl)
++argct;
switch (argct)
{
case 1:
if (TYPE_MAIN_VARIANT (type) != integer_type_node)
- pedwarn ("first argument of %q+D should be %<int%>", decl);
+ pedwarn (0, "first argument of %q+D should be %<int%>", decl);
break;
case 2:
if (TREE_CODE (type) != POINTER_TYPE
|| TREE_CODE (TREE_TYPE (type)) != POINTER_TYPE
|| (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type)))
!= char_type_node))
- pedwarn ("second argument of %q+D should be %<char **%>",
- decl);
+ pedwarn (0, "second argument of %q+D should be %<char **%>",
+ decl);
break;
case 3:
if (TREE_CODE (type) != POINTER_TYPE
|| TREE_CODE (TREE_TYPE (type)) != POINTER_TYPE
|| (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type)))
!= char_type_node))
- pedwarn ("third argument of %q+D should probably be "
- "%<char **%>", decl);
+ pedwarn (0, "third argument of %q+D should probably be "
+ "%<char **%>", decl);
break;
}
}
/* It is intentional that this message does not mention the third
argument because it's only mentioned in an appendix of the
standard. */
if (argct > 0 && (argct < 2 || argct > 3))
- pedwarn ("%q+D takes only zero or two arguments", decl);
+ pedwarn (0, "%q+D takes only zero or two arguments", decl);
}
/* True if pointers to distinct types T1 and T2 can be converted to
each other without an explicit cast. Only returns true for opaque
vector types. */
@@ -3071,24 +3072,24 @@ pointer_int_sum (enum tree_code resultco
/* The result is a pointer of the same type that is being added. */
tree result_type = TREE_TYPE (ptrop);
if (TREE_CODE (TREE_TYPE (result_type)) == VOID_TYPE)
{
- if (pedantic || warn_pointer_arith)
- pedwarn ("pointer of type %<void *%> used in arithmetic");
+ pedwarn (pedantic ? OPT_pedantic : OPT_Wpointer_arith,
+ "pointer of type %<void *%> used in arithmetic");
size_exp = integer_one_node;
}
else if (TREE_CODE (TREE_TYPE (result_type)) == FUNCTION_TYPE)
{
- if (pedantic || warn_pointer_arith)
- pedwarn ("pointer to a function used in arithmetic");
+ pedwarn (pedantic ? OPT_pedantic : OPT_Wpointer_arith,
+ "pointer to a function used in arithmetic");
size_exp = integer_one_node;
}
else if (TREE_CODE (TREE_TYPE (result_type)) == METHOD_TYPE)
{
- if (pedantic || warn_pointer_arith)
- pedwarn ("pointer to member function used in arithmetic");
+ pedwarn (pedantic ? OPT_pedantic : OPT_Wpointer_arith,
+ "pointer to member function used in arithmetic");
size_exp = integer_one_node;
}
else
size_exp = size_in_bytes (TREE_TYPE (result_type));
@@ -3592,11 +3593,12 @@ c_sizeof_or_alignof_type (tree type, boo
if (type_code == FUNCTION_TYPE)
{
if (is_sizeof)
{
if (complain && (pedantic || warn_pointer_arith))
- pedwarn ("invalid application of %<sizeof%> to a function type");
+ pedwarn (pedantic ? OPT_pedantic : OPT_Wpointer_arith,
+ "invalid application of %<sizeof%> to a function type");
else if (!complain)
return error_mark_node;
value = size_one_node;
}
else
@@ -3604,11 +3606,12 @@ c_sizeof_or_alignof_type (tree type, boo
}
else if (type_code == VOID_TYPE || type_code == ERROR_MARK)
{
if (type_code == VOID_TYPE
&& complain && (pedantic || warn_pointer_arith))
- pedwarn ("invalid application of %qs to a void type", op_name);
+ pedwarn (pedantic ? OPT_pedantic : OPT_Wpointer_arith,
+ "invalid application of %qs to a void type", op_name);
else if (!complain)
return error_mark_node;
value = size_one_node;
}
else if (!COMPLETE_TYPE_P (type))
@@ -4470,12 +4473,13 @@ c_add_case_label (splay_tree cases, tree
error ("pointers are not permitted as case values");
goto error_out;
}
/* Case ranges are a GNU extension. */
- if (high_value && pedantic)
- pedwarn ("range expressions in switch statements are non-standard");
+ if (high_value)
+ pedwarn (OPT_pedantic,
+ "range expressions in switch statements are non-standard");
type = TREE_TYPE (cond);
if (low_value)
{
low_value = check_case_value (low_value);
@@ -4784,12 +4788,11 @@ c_do_switch_warnings (splay_tree cases,
tree
finish_label_address_expr (tree label)
{
tree result;
- if (pedantic)
- pedwarn ("taking the address of a label is non-standard");
+ pedwarn (OPT_pedantic, "taking the address of a label is non-standard");
if (label == error_mark_node)
return error_mark_node;
label = lookup_label (label);
Index: gcc/c-parser.c
===================================================================
--- gcc/c-parser.c (revision 138044)
+++ gcc/c-parser.c (working copy)
@@ -958,13 +958,12 @@ static tree c_parser_objc_keywordexpr (c
static void
c_parser_translation_unit (c_parser *parser)
{
if (c_parser_next_token_is (parser, CPP_EOF))
{
- if (pedantic)
- pedwarn ("%HISO C forbids an empty translation unit",
- &c_parser_peek_token (parser)->location);
+ pedwarn (OPT_pedantic, "%HISO C forbids an empty translation unit",
+ &c_parser_peek_token (parser)->location);
}
else
{
void *obstack_position = obstack_alloc (&parser_obstack, 0);
do
@@ -1044,13 +1043,13 @@ c_parser_external_declaration (c_parser
default:
goto decl_or_fndef;
}
break;
case CPP_SEMICOLON:
- if (pedantic)
- pedwarn ("%HISO C does not allow extra %<;%> outside of a function",
- &c_parser_peek_token (parser)->location);
+ pedwarn (OPT_pedantic,
+ "%HISO C does not allow extra %<;%> outside of a function",
+ &c_parser_peek_token (parser)->location);
c_parser_consume_token (parser);
break;
case CPP_PRAGMA:
c_parser_pragma (parser, pragma_external);
break;
@@ -1160,11 +1159,11 @@ c_parser_declaration_or_fndef (c_parser
if (empty_ok)
shadow_tag (specs);
else
{
shadow_tag_warned (specs, 1);
- pedwarn ("%Hempty declaration", &here);
+ pedwarn (0, "%Hempty declaration", &here);
}
c_parser_consume_token (parser);
return;
}
pending_xref_error ();
@@ -1196,12 +1195,12 @@ c_parser_declaration_or_fndef (c_parser
tree asm_name = NULL_TREE;
tree postfix_attrs = NULL_TREE;
if (!diagnosed_no_specs && !specs->declspecs_seen_p)
{
diagnosed_no_specs = true;
- pedwarn ("%Hdata definition has no type or storage class",
- &here);
+ pedwarn (0, "%Hdata definition has no type or storage class",
+ &here);
}
/* Having seen a data definition, there cannot now be a
function definition. */
fndef_ok = false;
if (c_parser_next_token_is_keyword (parser, RID_ASM))
@@ -1266,12 +1265,11 @@ c_parser_declaration_or_fndef (c_parser
return;
}
/* Function definition (nested or otherwise). */
if (nested)
{
- if (pedantic)
- pedwarn ("%HISO C forbids nested functions", &here);
+ pedwarn (OPT_pedantic, "%HISO C forbids nested functions", &here);
c_push_function_context ();
}
if (!start_function (specs, declarator, all_prefix_attrs))
{
/* This can appear in many cases looking nothing like a
@@ -1661,12 +1659,13 @@ c_parser_enum_specifier (c_parser *parse
seen_comma = true;
c_parser_consume_token (parser);
}
if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
{
- if (seen_comma && pedantic && !flag_isoc99)
- pedwarn ("%Hcomma at end of enumerator list", &comma_loc);
+ if (seen_comma && !flag_isoc99)
+ pedwarn (OPT_pedantic, "%Hcomma at end of enumerator list",
+ &comma_loc);
c_parser_consume_token (parser);
break;
}
if (!seen_comma)
{
@@ -1693,11 +1692,12 @@ c_parser_enum_specifier (c_parser *parse
/* In ISO C, enumerated types can be referred to only if already
defined. */
if (pedantic && !COMPLETE_TYPE_P (ret.spec))
{
gcc_assert (ident);
- pedwarn ("%HISO C forbids forward references to %<enum%> types",
+ pedwarn (OPT_pedantic,
+ "%HISO C forbids forward references to %<enum%> types",
&ident_loc);
}
return ret;
}
@@ -1818,13 +1818,13 @@ c_parser_struct_or_union_specifier (c_pa
{
tree decls;
/* Parse any stray semicolon. */
if (c_parser_next_token_is (parser, CPP_SEMICOLON))
{
- if (pedantic)
- pedwarn ("%Hextra semicolon in struct or union specified",
- &c_parser_peek_token (parser)->location);
+ pedwarn (OPT_pedantic,
+ "%Hextra semicolon in struct or union specified",
+ &c_parser_peek_token (parser)->location);
c_parser_consume_token (parser);
continue;
}
/* Stop if at the end of the struct or union contents. */
if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
@@ -1848,12 +1848,12 @@ c_parser_struct_or_union_specifier (c_pa
if (c_parser_next_token_is (parser, CPP_SEMICOLON))
c_parser_consume_token (parser);
else
{
if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
- pedwarn ("%Hno semicolon at end of struct or union",
- &c_parser_peek_token (parser)->location);
+ pedwarn (0, "%Hno semicolon at end of struct or union",
+ &c_parser_peek_token (parser)->location);
else
{
c_parser_error (parser, "expected %<;%>");
c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL);
break;
@@ -1940,13 +1940,13 @@ c_parser_struct_declaration (c_parser *p
if (c_parser_next_token_is (parser, CPP_SEMICOLON))
{
tree ret;
if (!specs->type_seen_p)
{
- if (pedantic)
- pedwarn ("%HISO C forbids member declarations with no members",
- &decl_loc);
+ pedwarn (OPT_pedantic,
+ "%HISO C forbids member declarations with no members",
+ &decl_loc);
shadow_tag_warned (specs, pedantic);
ret = NULL_TREE;
}
else
{
@@ -2995,12 +2995,12 @@ c_parser_braced_init (c_parser *parser,
push_init_level (0);
else
really_start_incremental_init (type);
if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
{
- if (pedantic)
- pedwarn ("%HISO C forbids empty initializer braces", &brace_loc);
+ pedwarn (OPT_pedantic, "%HISO C forbids empty initializer braces",
+ &brace_loc);
}
else
{
/* Parse a non-empty initializer list, possibly with a trailing
comma. */
@@ -3040,16 +3040,14 @@ c_parser_initelt (c_parser *parser)
if (c_parser_next_token_is (parser, CPP_NAME)
&& c_parser_peek_2nd_token (parser)->type == CPP_COLON)
{
/* Old-style structure member designator. */
set_init_label (c_parser_peek_token (parser)->value);
- if (pedantic)
- {
- /* Use the colon as the error location. */
- pedwarn ("%Hobsolete use of designated initializer with %<:%>",
- &c_parser_peek_2nd_token (parser)->location);
- }
+ /* Use the colon as the error location. */
+ pedwarn (OPT_pedantic,
+ "%Hobsolete use of designated initializer with %<:%>",
+ &c_parser_peek_2nd_token (parser)->location);
c_parser_consume_token (parser);
c_parser_consume_token (parser);
}
else
{
@@ -3173,12 +3171,13 @@ c_parser_initelt (c_parser *parser)
second = NULL_TREE;
if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
{
c_parser_consume_token (parser);
set_init_index (first, second);
- if (pedantic && second)
- pedwarn ("%HISO C forbids specifying range of "
+ if (second)
+ pedwarn (OPT_pedantic,
+ "%HISO C forbids specifying range of "
"elements to initialize", &ellipsis_loc);
}
else
c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE,
"expected %<]%>");
@@ -3186,23 +3185,24 @@ c_parser_initelt (c_parser *parser)
}
if (des_seen >= 1)
{
if (c_parser_next_token_is (parser, CPP_EQ))
{
- if (pedantic && !flag_isoc99)
- pedwarn ("%HISO C90 forbids specifying subobject "
+ if (!flag_isoc99)
+ pedwarn (OPT_pedantic,
+ "%HISO C90 forbids specifying subobject "
"to initialize", &des_loc);
c_parser_consume_token (parser);
}
else
{
if (des_seen == 1)
{
- if (pedantic)
- pedwarn ("%Hobsolete use of designated initializer "
- "without %<=%>",
- &c_parser_peek_token (parser)->location);
+ pedwarn (OPT_pedantic,
+ "%Hobsolete use of designated initializer "
+ "without %<=%>",
+ &c_parser_peek_token (parser)->location);
}
else
{
struct c_expr init;
init.value = error_mark_node;
@@ -3349,12 +3349,11 @@ c_parser_compound_statement_nostart (c_p
else
break;
}
c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
}
- if (pedantic)
- pedwarn ("%HISO C forbids label declarations", &err_loc);
+ pedwarn (OPT_pedantic, "%HISO C forbids label declarations", &err_loc);
}
/* We must now have at least one statement, label or declaration. */
if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
{
c_parser_error (parser, "expected declaration or statement");
@@ -3380,14 +3379,15 @@ c_parser_compound_statement_nostart (c_p
else if (!last_label
&& c_parser_next_token_starts_declspecs (parser))
{
last_label = false;
c_parser_declaration_or_fndef (parser, true, true, true, true);
- if (last_stmt
- && ((pedantic && !flag_isoc99)
- || warn_declaration_after_statement))
- pedwarn_c90 ("%HISO C90 forbids mixed declarations and code",
+ if (last_stmt)
+ pedwarn_c90 ((pedantic && !flag_isoc99)
+ ? OPT_pedantic
+ : OPT_Wdeclaration_after_statement,
+ "%HISO C90 forbids mixed declarations and code",
&loc);
last_stmt = false;
}
else if (!last_label
&& c_parser_next_token_is_keyword (parser, RID_EXTENSION))
@@ -3408,14 +3408,15 @@ c_parser_compound_statement_nostart (c_p
last_label = false;
c_parser_declaration_or_fndef (parser, true, true, true, true);
/* Following the old parser, __extension__ does not
disable this diagnostic. */
restore_extension_diagnostics (ext);
- if (last_stmt
- && ((pedantic && !flag_isoc99)
- || warn_declaration_after_statement))
- pedwarn_c90 ("%HISO C90 forbids mixed declarations and code",
+ if (last_stmt)
+ pedwarn_c90 ((pedantic && !flag_isoc99)
+ ? OPT_pedantic
+ : OPT_Wdeclaration_after_statement,
+ "%HISO C90 forbids mixed declarations and code",
&loc);
last_stmt = false;
}
else
goto statement;
@@ -4418,13 +4419,13 @@ c_parser_conditional_expression (c_parse
return cond;
cond = default_function_array_conversion (cond);
c_parser_consume_token (parser);
if (c_parser_next_token_is (parser, CPP_COLON))
{
- if (pedantic)
- pedwarn ("%HISO C forbids omitting the middle term of a ?: expression",
- &c_parser_peek_token (parser)->location);
+ pedwarn (OPT_pedantic,
+ "%HISO C forbids omitting the middle term of a ?: expression",
+ &c_parser_peek_token (parser)->location);
/* Make sure first operand is calculated only once. */
exp1.value = save_expr (default_conversion (cond.value));
cond.value = c_objc_common_truthvalue_conversion (exp1.value);
skip_evaluation += cond.value == truthvalue_true_node;
}
@@ -5122,13 +5123,12 @@ c_parser_postfix_expression (c_parser *p
}
stmt = c_begin_stmt_expr ();
c_parser_compound_statement_nostart (parser);
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
"expected %<)%>");
- if (pedantic)
- pedwarn ("%HISO C forbids braced-groups within expressions",
- &here);
+ pedwarn (OPT_pedantic,
+ "%HISO C forbids braced-groups within expressions", &here);
expr.value = c_finish_stmt_expr (stmt);
expr.original_code = ERROR_MARK;
}
else if (c_token_starts_typename (c_parser_peek_2nd_token (parser)))
{
@@ -5484,12 +5484,13 @@ c_parser_postfix_expression_after_paren_
}
init = c_parser_braced_init (parser, type, false);
finish_init ();
maybe_warn_string_init (type, init);
- if (pedantic && !flag_isoc99)
- pedwarn ("%HISO C90 forbids compound literals", &start_loc);
+ if (!flag_isoc99)
+ pedwarn (OPT_pedantic, "%HISO C90 forbids compound literals",
+ &start_loc);
expr.value = build_compound_literal (type, init.value);
expr.original_code = ERROR_MARK;
return c_parser_postfix_expression_after_primary (parser, expr);
}
@@ -5786,13 +5787,13 @@ c_parser_objc_class_instance_variables (
{
tree decls;
/* Parse any stray semicolon. */
if (c_parser_next_token_is (parser, CPP_SEMICOLON))
{
- if (pedantic)
- pedwarn ("%Hextra semicolon in struct or union specified",
- &c_parser_peek_token (parser)->location);
+ pedwarn (OPT_pedantic,
+ "%Hextra semicolon in struct or union specified",
+ &c_parser_peek_token (parser)->location);
c_parser_consume_token (parser);
continue;
}
/* Stop if at the end of the instance variables. */
if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
@@ -6004,13 +6005,13 @@ c_parser_objc_method_definition (c_parse
parser->objc_pq_context = true;
decl = c_parser_objc_method_decl (parser);
if (c_parser_next_token_is (parser, CPP_SEMICOLON))
{
c_parser_consume_token (parser);
- if (pedantic)
- pedwarn ("%Hextra semicolon in method definition specified",
- &c_parser_peek_token (parser)->location);
+ pedwarn (OPT_pedantic,
+ "%Hextra semicolon in method definition specified",
+ &c_parser_peek_token (parser)->location);
}
if (!c_parser_next_token_is (parser, CPP_OPEN_BRACE))
{
c_parser_error (parser, "expected %<{%>");
return;
@@ -6042,14 +6043,13 @@ c_parser_objc_methodprotolist (c_parser
{
/* The list is terminated by @end. */
switch (c_parser_peek_token (parser)->type)
{
case CPP_SEMICOLON:
- if (pedantic)
- pedwarn ("%HISO C does not allow extra %<;%> "
- "outside of a function",
- &c_parser_peek_token (parser)->location);
+ pedwarn (OPT_pedantic, "%HISO C does not allow extra %<;%> "
+ "outside of a function",
+ &c_parser_peek_token (parser)->location);
c_parser_consume_token (parser);
break;
case CPP_PLUS:
case CPP_MINUS:
c_parser_objc_methodproto (parser);
Index: gcc/cp/typeck.c
===================================================================
--- gcc/cp/typeck.c (revision 138044)
+++ gcc/cp/typeck.c (working copy)
@@ -509,13 +509,14 @@ composite_pointer_type (tree t1, tree t2
if (TREE_CODE (t1) == POINTER_TYPE && VOID_TYPE_P (TREE_TYPE (t1)))
{
tree attributes;
tree result_type;
- if (pedantic && TYPE_PTRFN_P (t2) && (complain & tf_error))
- pedwarn ("ISO C++ forbids %s between pointer of type %<void *%> "
- "and pointer-to-function", location);
+ if (TYPE_PTRFN_P (t2) && (complain & tf_error))
+ pedwarn (OPT_pedantic, "ISO C++ forbids %s "
+ "between pointer of type %<void *%> and pointer-to-function",
+ location);
result_type
= cp_build_qualified_type (void_type_node,
(cp_type_quals (TREE_TYPE (t1))
| cp_type_quals (TREE_TYPE (t2))));
result_type = build_pointer_type (result_type);
@@ -1276,12 +1277,13 @@ cxx_sizeof_or_alignof_type (tree type, e
return error_mark_node;
type = non_reference (type);
if (TREE_CODE (type) == METHOD_TYPE)
{
- if (complain && (pedantic || warn_pointer_arith))
- pedwarn ("invalid application of %qs to a member function",
+ if (complain)
+ pedwarn (pedantic ? OPT_pedantic : OPT_Wpointer_arith,
+ "invalid application of %qs to a member function",
operator_name_info[(int) op].name);
value = size_one_node;
}
dependent_p = dependent_type_p (type);
@@ -2594,12 +2596,12 @@ build_array_ref (tree array, tree idx)
{
if (!cxx_mark_addressable (array))
return error_mark_node;
}
- if (pedantic && !lvalue_p (array))
- pedwarn ("ISO C++ forbids subscripting non-lvalue array");
+ if (!lvalue_p (array))
+ pedwarn (OPT_pedantic, "ISO C++ forbids subscripting non-lvalue array");
/* Note in C++ it is valid to subscript a `register' array, since
it is valid to take the address of something with that
storage specification. */
if (extra_warnings)
@@ -2820,12 +2822,13 @@ cp_build_function_call (tree function, t
mark_used (function);
fndecl = function;
/* Convert anything with function type to a pointer-to-function. */
- if (pedantic && DECL_MAIN_P (function) && (complain & tf_error))
- pedwarn ("ISO C++ forbids calling %<::main%> from within program");
+ if (DECL_MAIN_P (function) && (complain & tf_error))
+ pedwarn (OPT_pedantic,
+ "ISO C++ forbids calling %<::main%> from within program");
/* Differs from default_conversion by not setting TREE_ADDRESSABLE
(because calling an inline function does not mean the function
needs to be separately compiled). */
@@ -4099,19 +4102,16 @@ pointer_diff (tree op0, tree op1, tree p
tree target_type = TREE_TYPE (ptrtype);
if (!complete_type_or_else (target_type, NULL_TREE))
return error_mark_node;
- if (pedantic || warn_pointer_arith)
- {
- if (TREE_CODE (target_type) == VOID_TYPE)
- permerror ("ISO C++ forbids using pointer of type %<void *%> in subtraction");
- if (TREE_CODE (target_type) == FUNCTION_TYPE)
- permerror ("ISO C++ forbids using pointer to a function in subtraction");
- if (TREE_CODE (target_type) == METHOD_TYPE)
- permerror ("ISO C++ forbids using pointer to a method in subtraction");
- }
+ if (TREE_CODE (target_type) == VOID_TYPE)
+ permerror ("ISO C++ forbids using pointer of type %<void *%> in subtraction");
+ if (TREE_CODE (target_type) == FUNCTION_TYPE)
+ permerror ("ISO C++ forbids using pointer to a function in subtraction");
+ if (TREE_CODE (target_type) == METHOD_TYPE)
+ permerror ("ISO C++ forbids using pointer to a method in subtraction");
/* First do the subtraction as integers;
then drop through to build the divide operator. */
op0 = cp_build_binary_op (MINUS_EXPR,
@@ -4557,11 +4557,11 @@ cp_build_unary_op (enum tree_code code,
{
tree type = build_pointer_type (TREE_TYPE (argtype));
arg = build1 (CONVERT_EXPR, type, arg);
return arg;
}
- else if (pedantic && DECL_MAIN_P (arg))
+ else if (DECL_MAIN_P (arg))
{
/* ARM $3.4 */
if (complain & tf_error)
permerror ("ISO C++ forbids taking address of function %<::main%>");
else
@@ -4653,11 +4653,11 @@ cp_build_unary_op (enum tree_code code,
case FLOAT_EXPR:
case FIX_TRUNC_EXPR:
/* Even if we're not being pedantic, we cannot allow this
extension when we're instantiating in a SFINAE
context. */
- if (! lvalue_p (arg) && (pedantic || complain == tf_none))
+ if (! lvalue_p (arg) && complain == tf_none)
{
if (complain & tf_error)
permerror ("ISO C++ forbids taking the address of a cast to a non-lvalue expression");
else
return error_mark_node;
@@ -5441,11 +5441,12 @@ convert_member_func_to_ptr (tree type, t
intype = TREE_TYPE (expr);
gcc_assert (TYPE_PTRMEMFUNC_P (intype)
|| TREE_CODE (intype) == METHOD_TYPE);
if (pedantic || warn_pmf2ptr)
- pedwarn ("converting from %qT to %qT", intype, type);
+ pedwarn (pedantic ? OPT_pedantic : OPT_Wpmf_conversions,
+ "converting from %qT to %qT", intype, type);
if (TREE_CODE (intype) == METHOD_TYPE)
expr = build_addr_func (expr);
else if (TREE_CODE (expr) == PTRMEM_CST)
expr = build_address (PTRMEM_CST_MEMBER (expr));
@@ -6978,11 +6979,10 @@ check_return_expr (tree retval, bool *no
its side-effects. */
finish_expr_stmt (retval);
else
permerror ("return-statement with a value, in function "
"returning 'void'");
-
current_function_returns_null = 1;
/* There's really no value to return, after all. */
return NULL_TREE;
}
@@ -7345,11 +7345,12 @@ cp_apply_type_quals_to_decl (int type_qu
a function type), but DR 295 makes the code well-formed by
dropping the extra qualifiers. */
if (pedantic)
{
tree bad_type = build_qualified_type (type, type_quals);
- pedwarn ("ignoring %qV qualifiers added to function type %qT",
+ pedwarn (OPT_pedantic,
+ "ignoring %qV qualifiers added to function type %qT",
bad_type, type);
}
TREE_TYPE (decl) = TYPE_MAIN_VARIANT (type);
return;
Index: gcc/cp/decl.c
===================================================================
--- gcc/cp/decl.c (revision 138044)
+++ gcc/cp/decl.c (working copy)
@@ -3811,13 +3811,12 @@ check_tag_decl (cp_decl_specifier_seq *d
return NULL_TREE;
}
/* Anonymous unions are objects, so they can have specifiers. */;
SET_ANON_AGGR_TYPE_P (declared_type);
- if (TREE_CODE (declared_type) != UNION_TYPE && pedantic
- && !in_system_header)
- pedwarn ("ISO C++ prohibits anonymous structs");
+ if (TREE_CODE (declared_type) != UNION_TYPE && !in_system_header)
+ pedwarn (OPT_pedantic, "ISO C++ prohibits anonymous structs");
}
else
{
if (declspecs->specs[(int)ds_inline]
@@ -7002,12 +7001,12 @@ check_static_variable_definition (tree d
}
else if (!CP_TYPE_CONST_P (type))
error ("ISO C++ forbids in-class initialization of non-const "
"static member %qD",
decl);
- else if (pedantic && !INTEGRAL_TYPE_P (type))
- pedwarn ("ISO C++ forbids initialization of member constant "
+ else if (!INTEGRAL_TYPE_P (type))
+ pedwarn (OPT_pedantic, "ISO C++ forbids initialization of member constant "
"%qD of non-integral type %qT", decl, type);
return 0;
}
@@ -7080,16 +7079,16 @@ compute_array_index_type (tree name, tre
error ("size of array is negative");
size = integer_one_node;
}
/* As an extension we allow zero-sized arrays. We always allow
them in system headers because glibc uses them. */
- else if (integer_zerop (size) && pedantic && !in_system_header)
+ else if (integer_zerop (size) && !in_system_header)
{
if (name)
- pedwarn ("ISO C++ forbids zero-size array %qD", name);
+ pedwarn (OPT_pedantic, "ISO C++ forbids zero-size array %qD", name);
else
- pedwarn ("ISO C++ forbids zero-size array");
+ pedwarn (OPT_pedantic, "ISO C++ forbids zero-size array");
}
}
else if (TREE_CONSTANT (size))
{
/* `(int) &fn' is not a valid array bound. */
@@ -7101,13 +7100,13 @@ compute_array_index_type (tree name, tre
size = integer_one_node;
}
else if (pedantic && warn_vla != 0)
{
if (name)
- pedwarn ("ISO C++ forbids variable length array %qD", name);
+ pedwarn (OPT_Wvla, "ISO C++ forbids variable length array %qD", name);
else
- pedwarn ("ISO C++ forbids variable length array");
+ pedwarn (OPT_Wvla, "ISO C++ forbids variable length array");
}
else if (warn_vla > 0)
{
if (name)
warning (OPT_Wvla,
@@ -7734,11 +7733,12 @@ grokdeclarator (const cp_declarator *dec
else if (in_system_header || flag_ms_extensions)
/* Allow it, sigh. */;
else if (! is_main)
permerror ("ISO C++ forbids declaration of %qs with no type", name);
else if (pedantic)
- pedwarn ("ISO C++ forbids declaration of %qs with no type", name);
+ pedwarn (OPT_pedantic,
+ "ISO C++ forbids declaration of %qs with no type", name);
else
warning (OPT_Wreturn_type,
"ISO C++ forbids declaration of %qs with no type", name);
type = integer_type_node;
@@ -7789,11 +7789,12 @@ grokdeclarator (const cp_declarator *dec
else
{
ok = 1;
if (!explicit_int && !defaulted_int && !explicit_char && pedantic)
{
- pedwarn ("long, short, signed or unsigned used invalidly for %qs",
+ pedwarn (OPT_pedantic,
+ "long, short, signed or unsigned used invalidly for %qs",
name);
if (flag_pedantic_errors)
ok = 0;
}
}
@@ -7894,11 +7895,12 @@ grokdeclarator (const cp_declarator *dec
a function type), but DR 295 makes the code well-formed by
dropping the extra qualifiers. */
if (pedantic)
{
tree bad_type = build_qualified_type (type, type_quals);
- pedwarn ("ignoring %qV qualifiers added to function type %qT",
+ pedwarn (OPT_pedantic,
+ "ignoring %qV qualifiers added to function type %qT",
bad_type, type);
}
type_quals = TYPE_UNQUALIFIED;
}
type_quals |= cp_type_quals (type);
@@ -9122,14 +9124,16 @@ grokdeclarator (const cp_declarator *dec
&& (storage_class == sc_static
|| declspecs->specs[(int)ds_inline])
&& pedantic)
{
if (storage_class == sc_static)
- pedwarn ("%<static%> specified invalid for function %qs "
+ pedwarn (OPT_pedantic,
+ "%<static%> specified invalid for function %qs "
"declared out of global scope", name);
else
- pedwarn ("%<inline%> specifier invalid for function %qs "
+ pedwarn (OPT_pedantic,
+ "%<inline%> specifier invalid for function %qs "
"declared out of global scope", name);
}
if (ctype == NULL_TREE)
{
@@ -9213,13 +9217,13 @@ grokdeclarator (const cp_declarator *dec
error ("static member %qD declared %<register%>", decl);
storage_class = sc_none;
}
if (storage_class == sc_extern && pedantic)
{
- pedwarn ("cannot explicitly declare member %q#D to have "
- "extern linkage",
- decl);
+ pedwarn (OPT_pedantic,
+ "cannot explicitly declare member %q#D to have "
+ "extern linkage", decl);
storage_class = sc_none;
}
}
}
@@ -10102,12 +10106,12 @@ grok_op_properties (tree decl, bool comp
{
TREE_PURPOSE (argtypes) = NULL_TREE;
if (operator_code == POSTINCREMENT_EXPR
|| operator_code == POSTDECREMENT_EXPR)
{
- if (pedantic)
- pedwarn ("%qD cannot have default arguments", decl);
+ pedwarn (OPT_pedantic, "%qD cannot have default arguments",
+ decl);
}
else
{
error ("%qD cannot have default arguments", decl);
return false;
Index: gcc/cp/call.c
===================================================================
--- gcc/cp/call.c (revision 138044)
+++ gcc/cp/call.c (working copy)
@@ -3402,12 +3402,13 @@ build_conditional_expr (tree arg1, tree
omitted. (So that `a ? : c' is roughly equivalent to `a ? a :
c'.) If the second operand is omitted, make sure it is
calculated only once. */
if (!arg2)
{
- if (pedantic && (complain & tf_error))
- pedwarn ("ISO C++ forbids omitting the middle term of a ?: expression");
+ if (complain & tf_error)
+ pedwarn (OPT_pedantic,
+ "ISO C++ forbids omitting the middle term of a ?: expression");
/* Make sure that lvalues remain lvalues. See g++.oliva/ext1.C. */
if (real_lvalue_p (arg1))
arg2 = arg1 = stabilize_reference (arg1);
else
@@ -6758,11 +6759,11 @@ tweak:
winner = -1, w = cand2, l = cand1;
if (winner)
{
if (warn)
{
- warning (0,
+ pedwarn (0,
"ISO C++ says that these are ambiguous, even "
"though the worst conversion for the first is better than "
"the worst conversion for the second:");
print_z_candidate (_("candidate 1:"), w);
print_z_candidate (_("candidate 2:"), l);
Index: gcc/cp/error.c
===================================================================
--- gcc/cp/error.c (revision 138044)
+++ gcc/cp/error.c (working copy)
@@ -2683,11 +2683,11 @@ maybe_warn_cpp0x (const char* str)
{
if ((cxx_dialect == cxx98) && !in_system_header)
/* We really want to suppress this warning in system headers,
because libstdc++ uses variadic templates even when we aren't
in C++0x mode. */
- pedwarn ("%s only available with -std=c++0x", str);
+ pedwarn (0, "%s only available with -std=c++0x", str);
}
/* Warn about the use of variadic templates when appropriate. */
void
maybe_warn_variadic_templates (void)
Index: gcc/cp/typeck2.c
===================================================================
--- gcc/cp/typeck2.c (revision 138044)
+++ gcc/cp/typeck2.c (working copy)
@@ -343,11 +343,11 @@ cxx_incomplete_type_diagnostic (const_tr
void (*p_msg) (const char *, ...) ATTRIBUTE_GCC_CXXDIAG(1,2);
if (diag_type == 1)
p_msg = warning0;
else if (diag_type == 2)
- p_msg = pedwarn;
+ p_msg = pedwarn0;
else
p_msg = error;
/* Avoid duplicate error message. */
if (TREE_CODE (type) == ERROR_MARK)
Index: gcc/cp/pt.c
===================================================================
--- gcc/cp/pt.c (revision 138044)
+++ gcc/cp/pt.c (working copy)
@@ -14608,12 +14608,13 @@ do_decl_instantiation (tree decl, tree s
if (storage == NULL_TREE)
;
else if (storage == ridpointers[(int) RID_EXTERN])
{
- if (pedantic && !in_system_header && (cxx_dialect == cxx98))
- pedwarn ("ISO C++ 1998 forbids the use of %<extern%> on explicit "
+ if (!in_system_header && (cxx_dialect == cxx98))
+ pedwarn (OPT_pedantic,
+ "ISO C++ 1998 forbids the use of %<extern%> on explicit "
"instantiations");
extern_p = 1;
}
else
error ("storage class %qD applied to template instantiation", storage);
@@ -14695,20 +14696,21 @@ do_type_instantiation (tree t, tree stor
return;
}
if (storage != NULL_TREE)
{
- if (pedantic && !in_system_header)
+ if (!in_system_header)
{
if (storage == ridpointers[(int) RID_EXTERN])
{
if (cxx_dialect == cxx98)
- pedwarn("ISO C++ 1998 forbids the use of %<extern%> on "
+ pedwarn(OPT_pedantic,
+ "ISO C++ 1998 forbids the use of %<extern%> on "
"explicit instantiations");
}
else
- pedwarn("ISO C++ forbids the use of %qE on explicit "
+ pedwarn(OPT_pedantic, "ISO C++ forbids the use of %qE on explicit "
"instantiations", storage);
}
if (storage == ridpointers[(int) RID_INLINE])
nomem_p = 1;
Index: gcc/cp/name-lookup.c
===================================================================
--- gcc/cp/name-lookup.c (revision 138044)
+++ gcc/cp/name-lookup.c (working copy)
@@ -722,14 +722,14 @@ pushdecl_maybe_friend (tree x, bool is_f
|| DECL_FUNCTION_TEMPLATE_P (x))
&& is_overloaded_fn (t))
/* Don't do anything just yet. */;
else if (t == wchar_decl_node)
{
- if (pedantic && ! DECL_IN_SYSTEM_HEADER (x))
- pedwarn ("redeclaration of %<wchar_t%> as %qT",
+ if (! DECL_IN_SYSTEM_HEADER (x))
+ pedwarn (OPT_pedantic, "redeclaration of %<wchar_t%> as %qT",
TREE_TYPE (x));
-
+
/* Throw away the redeclaration. */
POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, t);
}
else
{
@@ -794,14 +794,15 @@ pushdecl_maybe_friend (tree x, bool is_f
TYPE_RAISES_EXCEPTIONS (TREE_TYPE (previous));
if (!comp_except_specs (previous_exception_spec,
x_exception_spec,
true))
{
- pedwarn ("declaration of %q#D with C language linkage", x);
- pedwarn ("conflicts with previous declaration %q+#D",
- previous);
- pedwarn ("due to different exception specifications");
+ pedwarn (0, "declaration of %q#D with C language linkage",
+ x);
+ pedwarn (0, "conflicts with previous declaration %q+#D",
+ previous);
+ pedwarn (0, "due to different exception specifications");
POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, error_mark_node);
}
}
}
}
Index: gcc/cp/parser.c
===================================================================
--- gcc/cp/parser.c (revision 138044)
+++ gcc/cp/parser.c (working copy)
@@ -2160,11 +2160,12 @@ cp_parser_check_decl_spec (cp_decl_speci
{
if (count > 2)
error ("%H%<long long long%> is too long for GCC", &location);
else if (pedantic && !in_system_header && warn_long_long
&& cxx_dialect == cxx98)
- pedwarn ("%HISO C++ 1998 does not support %<long long%>",
+ pedwarn (OPT_Wlong_long,
+ "%HISO C++ 1998 does not support %<long long%>",
&location);
}
else if (count > 1)
{
static const char *const decl_spec_names[] = {
@@ -3212,13 +3213,13 @@ cp_parser_primary_expression (cp_parser
a GNU statement-expression. */
if (cp_parser_allow_gnu_extensions_p (parser)
&& cp_lexer_next_token_is (parser->lexer, CPP_OPEN_BRACE))
{
/* Statement-expressions are not allowed by the standard. */
- if (pedantic)
- pedwarn ("%HISO C++ forbids braced-groups within expressions",
- &token->location);
+ pedwarn (OPT_pedantic,
+ "%HISO C++ forbids braced-groups within expressions",
+ &token->location);
/* And they're not allowed outside of a function-body; you
cannot, for example, write:
int i = ({ int j = 3; j + 1; });
@@ -4543,12 +4544,11 @@ cp_parser_postfix_expression (cp_parser
compound-literal expression. */
if (cp_parser_parse_definitely (parser))
{
/* Warn the user that a compound literal is not
allowed in standard C++. */
- if (pedantic)
- pedwarn ("ISO C++ forbids compound-literals");
+ pedwarn (OPT_pedantic, "ISO C++ forbids compound-literals");
/* For simplicity, we disallow compound literals in
constant-expressions. We could
allow compound literals of integer type, whose
initializer was a constant, in constant
expressions. Permitting that usage, as a further
@@ -7608,12 +7608,11 @@ cp_parser_jump_statement (cp_parser* par
case RID_GOTO:
/* Create the goto-statement. */
if (cp_lexer_next_token_is (parser->lexer, CPP_MULT))
{
/* Issue a warning about this use of a GNU extension. */
- if (pedantic)
- pedwarn ("%HISO C++ forbids computed gotos", &token->location);
+ pedwarn (OPT_pedantic, "%HISO C++ forbids computed gotos", &token->location);
/* Consume the '*' token. */
cp_lexer_consume_token (parser->lexer);
/* Parse the dependent expression. */
finish_goto_stmt (cp_parser_expression (parser, /*cast_p=*/false));
}
@@ -7748,12 +7747,12 @@ cp_parser_declaration_seq_opt (cp_parser
if (token->type == CPP_SEMICOLON)
{
/* A declaration consisting of a single semicolon is
invalid. Allow it unless we're being pedantic. */
cp_lexer_consume_token (parser->lexer);
- if (pedantic && !in_system_header)
- pedwarn ("extra %<;%>");
+ if (!in_system_header)
+ pedwarn (OPT_pedantic, "extra %<;%>");
continue;
}
/* If we're entering or exiting a region that's implicitly
extern "C", modify the lang context appropriately. */
@@ -11732,12 +11731,12 @@ cp_parser_enumerator_list (cp_parser* pa
/* Otherwise, consume the `,' and keep going. */
cp_lexer_consume_token (parser->lexer);
/* If the next token is a `}', there is a trailing comma. */
if (cp_lexer_next_token_is (parser->lexer, CPP_CLOSE_BRACE))
{
- if (pedantic && !in_system_header)
- pedwarn ("comma at end of enumerator list");
+ if (!in_system_header)
+ pedwarn (OPT_pedantic, "comma at end of enumerator list");
break;
}
}
}
@@ -14367,12 +14366,12 @@ cp_parser_initializer_list (cp_parser* p
if (cp_parser_allow_gnu_extensions_p (parser)
&& cp_lexer_next_token_is (parser->lexer, CPP_NAME)
&& cp_lexer_peek_nth_token (parser->lexer, 2)->type == CPP_COLON)
{
/* Warn the user that they are using an extension. */
- if (pedantic)
- pedwarn ("ISO C++ does not allow designated initializers");
+ pedwarn (OPT_pedantic,
+ "ISO C++ does not allow designated initializers");
/* Consume the identifier. */
identifier = cp_lexer_consume_token (parser->lexer)->u.value;
/* Consume the `:'. */
cp_lexer_consume_token (parser->lexer);
}
@@ -15384,12 +15383,12 @@ cp_parser_member_declaration (cp_parser*
Each member-declaration shall declare at least one member
name of the class. */
if (!decl_specifiers.any_specifiers_p)
{
cp_token *token = cp_lexer_peek_token (parser->lexer);
- if (pedantic && !in_system_header_at (token->location))
- pedwarn ("%Hextra %<;%>", &token->location);
+ if (!in_system_header_at (token->location))
+ pedwarn (OPT_pedantic, "%Hextra %<;%>", &token->location);
}
else
{
tree type;
Index: gcc/fortran/f95-lang.c
===================================================================
--- gcc/fortran/f95-lang.c (revision 138044)
+++ gcc/fortran/f95-lang.c (working copy)
@@ -602,12 +602,12 @@ gfc_mark_addressable (tree exp)
{
error ("global register variable %qs used in nested function",
IDENTIFIER_POINTER (DECL_NAME (x)));
return false;
}
- pedwarn ("register variable %qs used in nested function",
- IDENTIFIER_POINTER (DECL_NAME (x)));
+ pedwarn0 ("register variable %qs used in nested function",
+ IDENTIFIER_POINTER (DECL_NAME (x)));
}
else if (DECL_REGISTER (x) && !TREE_ADDRESSABLE (x))
{
if (TREE_PUBLIC (x))
{
@@ -627,11 +627,11 @@ gfc_mark_addressable (tree exp)
error ("cannot put object with volatile field into register");
return false;
}
#endif
- pedwarn ("address of register variable %qs requested",
+ pedwarn0 ("address of register variable %qs requested",
IDENTIFIER_POINTER (DECL_NAME (x)));
}
/* drops in */
case FUNCTION_DECL: