From 07317e6985727a04296a7c5cbdaed8e4555f3038 Mon Sep 17 00:00:00 2001 From: manu Date: Sun, 2 Mar 2008 15:45:29 +0000 Subject: [PATCH] 2008-03-02 Manuel Lopez-Ibanez PR 24924 * c-common.c (flag_permissive): Delete. (constant_expression_warnings): Check flags first. (constant_expression_error): New. * c-common.h (flag_permissive): Delete. (constant_expression_error): Declare. * flags.h (flag_permissive): Declare. Update description. * diagnostic.c (pedwarn): Update. (permerror): New. * diagnostic.h: (pedantic_error_kind): Rename as pedantic_warning_kind. (permissive_error_kind): New. * toplev.c (flag_permissive): Define. Update description. * toplev.h (permissive_error_kind): Declare. * c-errors.c (pedwarn_c99): Use pedantic_warning_kind. (pedwarn_c90): Use pedantic_warning_kind. * c-opts.c (c_common_post_options): flag_permissive does not affect flag_pedantic_errors. cp/ * class.c (finish_struct_anon): Use permerror instead of pedwarn. (check_field_decls): Likewise. (note_name_declared_in_class): Likewise. * call.c (build_new_op): Likewise. (convert_like_real): Likewise. (build_over_call): Likewise. * lex.c (unqualified_fn_lookup_error): Likewise. * parser.c (cp_parser_template_id): Likewise. * cvt.c (warn_ref_binding): Likewise. (convert_to_reference): Likewise. (ocp_convert): Likewise. (convert_to_void): Use error instead of pedwarn. * error.c (cp_cpp_error): Use pedantic_warning_kind. * decl.c (compute_array_index_type): Use constant_expression_error. testsuite/ * g++.dg/cpp/string-2.C: This is a warning now. * g++.dg/cpp/pedantic-errors.C: -pedantic-errors is not enabled by default, so add it. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@132817 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 20 ++++++++++++++++++++ gcc/c-common.c | 24 +++++++++++++++--------- gcc/c-common.h | 6 +----- gcc/c-errors.c | 4 ++-- gcc/c-opts.c | 12 ------------ gcc/cp/ChangeLog | 18 ++++++++++++++++++ gcc/cp/call.c | 14 +++++++------- gcc/cp/class.c | 26 +++++++++++++------------- gcc/cp/cvt.c | 14 +++++++------- gcc/cp/decl.c | 7 +------ gcc/cp/error.c | 2 +- gcc/cp/lex.c | 8 ++++---- gcc/cp/parser.c | 2 +- gcc/diagnostic.c | 22 +++++++++++++++++++++- gcc/diagnostic.h | 3 ++- gcc/flags.h | 4 ++++ gcc/testsuite/ChangeLog | 7 +++++++ gcc/testsuite/g++.dg/cpp/pedantic-errors.C | 5 +++++ gcc/testsuite/g++.dg/cpp/string-2.C | 5 ++--- gcc/toplev.c | 4 ++++ gcc/toplev.h | 1 + 21 files changed, 136 insertions(+), 72 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp/pedantic-errors.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 41e35e2..c2200cb 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,23 @@ +2008-03-02 Manuel Lopez-Ibanez + + PR 24924 + * c-common.c (flag_permissive): Delete. + (constant_expression_warnings): Check flags first. + (constant_expression_error): New. + * c-common.h (flag_permissive): Delete. + (constant_expression_error): Declare. + * flags.h (flag_permissive): Declare. Update description. + * diagnostic.c (pedwarn): Update. + (permerror): New. + * diagnostic.h: (pedantic_error_kind): Rename as pedantic_warning_kind. + (permissive_error_kind): New. + * toplev.c (flag_permissive): Define. Update description. + * toplev.h (permissive_error_kind): Declare. + * c-errors.c (pedwarn_c99): Use pedantic_warning_kind. + (pedwarn_c90): Use pedantic_warning_kind. + * c-opts.c (c_common_post_options): flag_permissive does not affect + flag_pedantic_errors. + 2008-03-02 Joseph Myers * libgcc2.c (__addvSI3, __addvsi3, __addvDI3, __subvSI3, diff --git a/gcc/c-common.c b/gcc/c-common.c index 9706d87..f3de12a 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -443,11 +443,6 @@ int flag_use_cxa_atexit = DEFAULT_USE_CXA_ATEXIT; int flag_use_cxa_get_exception_ptr = 2; -/* Nonzero means make the default pedwarns warnings instead of errors. - The value of this flag is ignored if -pedantic is specified. */ - -int flag_permissive; - /* Nonzero means to implement standard semantics for exception specifications, calling unexpected if an exception is thrown that doesn't match the specification. Zero means to treat them as @@ -927,14 +922,25 @@ fix_string_type (tree value) void constant_expression_warning (tree value) { + if (warn_overflow && pedantic + && (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"); +} + +/* The same as above but print an unconditional error. */ +void +constant_expression_error (tree value) +{ if ((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) - && warn_overflow - && pedantic) - pedwarn ("overflow in constant expression"); + && TREE_OVERFLOW (value)) + error ("overflow in constant expression"); } /* Print a warning if an expression had overflow in folding and its diff --git a/gcc/c-common.h b/gcc/c-common.h index 99209c7..a072710 100644 --- a/gcc/c-common.h +++ b/gcc/c-common.h @@ -584,11 +584,6 @@ extern int flag_use_cxa_atexit; extern int flag_use_cxa_get_exception_ptr; -/* Nonzero means make the default pedwarns warnings instead of errors. - The value of this flag is ignored if -pedantic is specified. */ - -extern int flag_permissive; - /* Nonzero means to implement standard semantics for exception specifications, calling unexpected if an exception is thrown that doesn't match the specification. Zero means to treat them as @@ -688,6 +683,7 @@ extern void binary_op_error (enum tree_code, tree, tree); extern tree fix_string_type (tree); struct varray_head_tag; extern void constant_expression_warning (tree); +extern void constant_expression_error (tree); extern bool strict_aliasing_warning (tree, tree, tree); extern void empty_if_body_warning (tree, tree); extern void warnings_for_convert_and_check (tree, tree, tree); diff --git a/gcc/c-errors.c b/gcc/c-errors.c index c85d397..dc47b76 100644 --- a/gcc/c-errors.c +++ b/gcc/c-errors.c @@ -38,7 +38,7 @@ pedwarn_c99 (const char *gmsgid, ...) va_start (ap, gmsgid); diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location, - flag_isoc99 ? pedantic_error_kind () : DK_WARNING); + flag_isoc99 ? pedantic_warning_kind () : DK_WARNING); report_diagnostic (&diagnostic); va_end (ap); } @@ -56,7 +56,7 @@ pedwarn_c90 (const char *gmsgid, ...) va_start (ap, gmsgid); diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location, - flag_isoc99 ? DK_WARNING : pedantic_error_kind ()); + flag_isoc99 ? DK_WARNING : pedantic_warning_kind ()); report_diagnostic (&diagnostic); va_end (ap); } diff --git a/gcc/c-opts.c b/gcc/c-opts.c index d7409ad..69c4d54 100644 --- a/gcc/c-opts.c +++ b/gcc/c-opts.c @@ -1107,18 +1107,6 @@ c_common_post_options (const char **pfilename) /* Adjust various flags for C++ based on command-line settings. */ if (c_dialect_cxx ()) { - if (!flag_permissive) - { - flag_pedantic_errors = 1; - /* FIXME: For consistency pedantic_errors should have the - same value in the front-end and in CPP. However, this - will break existing applications. The right fix is - disentagle flag_permissive from flag_pedantic_errors, - create a new diagnostic function permerror that is - controlled by flag_permissive and convert most C++ - pedwarns to this new function. - cpp_opts->pedantic_errors = 1; */ - } if (!flag_no_inline) { flag_inline_trees = 1; diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 6f61262..3c79d1d 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,21 @@ +2008-03-02 Manuel Lopez-Ibanez + + PR 24924 + * class.c (finish_struct_anon): Use permerror instead of pedwarn. + (check_field_decls): Likewise. + (note_name_declared_in_class): Likewise. + * call.c (build_new_op): Likewise. + (convert_like_real): Likewise. + (build_over_call): Likewise. + * lex.c (unqualified_fn_lookup_error): Likewise. + * parser.c (cp_parser_template_id): Likewise. + * cvt.c (warn_ref_binding): Likewise. + (convert_to_reference): Likewise. + (ocp_convert): Likewise. + (convert_to_void): Use error instead of pedwarn. + * error.c (cp_cpp_error): Use pedantic_warning_kind. + * decl.c (compute_array_index_type): Use constant_expression_error. + 2008-03-01 Douglas Gregor * parser.c (cp_lexer_next_token_is_decl_specifier_keyword): Note diff --git a/gcc/cp/call.c b/gcc/cp/call.c index a61638c..2ee8237 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -3857,10 +3857,10 @@ build_new_op (enum tree_code code, int flags, tree arg1, tree arg2, tree arg3, /* Look for an `operator++ (int)'. If they didn't have one, then we fall back to the old way of doing things. */ if (flags & LOOKUP_COMPLAIN) - pedwarn ("no %<%D(int)%> declared for postfix %qs, " - "trying prefix operator instead", - fnname, - operator_name_info[code].name); + permerror ("no %<%D(int)%> declared for postfix %qs, " + "trying prefix operator instead", + fnname, + operator_name_info[code].name); if (code == POSTINCREMENT_EXPR) code = PREINCREMENT_EXPR; else @@ -4343,9 +4343,9 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum, else if (t->kind == ck_identity) break; } - pedwarn ("invalid conversion from %qT to %qT", TREE_TYPE (expr), totype); + permerror ("invalid conversion from %qT to %qT", TREE_TYPE (expr), totype); if (fn) - pedwarn (" initializing argument %P of %qD", argnum, fn); + permerror (" initializing argument %P of %qD", argnum, fn); return cp_convert (totype, expr); } @@ -4955,7 +4955,7 @@ build_over_call (struct z_candidate *cand, int flags) tree base_binfo; if (convs[i]->bad_p) - pedwarn ("passing %qT as % argument of %q#D discards qualifiers", + permerror ("passing %qT as % argument of %q#D discards qualifiers", TREE_TYPE (argtype), fn); /* [class.mfct.nonstatic]: If a nonstatic member function of a class diff --git a/gcc/cp/class.c b/gcc/cp/class.c index 1a76816..500ddaa 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -2493,27 +2493,27 @@ finish_struct_anon (tree t) if (TREE_CODE (elt) != FIELD_DECL) { if (is_union) - pedwarn ("%q+#D invalid; an anonymous union can " - "only have non-static data members", elt); + permerror ("%q+#D invalid; an anonymous union can " + "only have non-static data members", elt); else - pedwarn ("%q+#D invalid; an anonymous struct can " - "only have non-static data members", elt); + permerror ("%q+#D invalid; an anonymous struct can " + "only have non-static data members", elt); continue; } if (TREE_PRIVATE (elt)) { if (is_union) - pedwarn ("private member %q+#D in anonymous union", elt); + permerror ("private member %q+#D in anonymous union", elt); else - pedwarn ("private member %q+#D in anonymous struct", elt); + permerror ("private member %q+#D in anonymous struct", elt); } else if (TREE_PROTECTED (elt)) { if (is_union) - pedwarn ("protected member %q+#D in anonymous union", elt); + permerror ("protected member %q+#D in anonymous union", elt); else - pedwarn ("protected member %q+#D in anonymous struct", elt); + permerror ("protected member %q+#D in anonymous struct", elt); } TREE_PRIVATE (elt) = TREE_PRIVATE (field); @@ -3044,7 +3044,7 @@ check_field_decls (tree t, tree *access_decls, user-defined constructor. */ if (constructor_name_p (DECL_NAME (x), t) && TYPE_HAS_USER_CONSTRUCTOR (t)) - pedwarn ("field %q+#D with same name as class", x); + permerror ("field %q+#D with same name as class", x); /* We set DECL_C_BIT_FIELD in grokbitfield. If the type and width are valid, we'll also set DECL_BIT_FIELD. */ @@ -6072,10 +6072,10 @@ resolve_address_of_overloaded_function (tree target_type, if (!(flags & tf_error)) return error_mark_node; - pedwarn ("assuming pointer to member %qD", fn); + permerror ("assuming pointer to member %qD", fn); if (!explained) { - pedwarn ("(a pointer to member can only be formed with %<&%E%>)", fn); + inform ("(a pointer to member can only be formed with %<&%E%>)", fn); explained = 1; } } @@ -6435,8 +6435,8 @@ note_name_declared_in_class (tree name, tree decl) A name N used in a class S shall refer to the same declaration in its context and when re-evaluated in the completed scope of S. */ - pedwarn ("declaration of %q#D", decl); - pedwarn ("changes meaning of %qD from %q+#D", + permerror ("declaration of %q#D", decl); + permerror ("changes meaning of %qD from %q+#D", DECL_NAME (OVL_CURRENT (decl)), (tree) n->value); } } diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c index a75036f..ee5759d 100644 --- a/gcc/cp/cvt.c +++ b/gcc/cp/cvt.c @@ -379,7 +379,7 @@ warn_ref_binding (tree reftype, tree intype, tree decl) msg = "conversion to non-const reference type %q#T from" " rvalue of type %qT"; - pedwarn (msg, reftype, intype); + permerror (msg, reftype, intype); } } @@ -449,8 +449,8 @@ convert_to_reference (tree reftype, tree expr, int convtype, if (! (convtype & CONV_CONST) && !at_least_as_qualified_p (ttl, ttr)) - pedwarn ("conversion from %qT to %qT discards qualifiers", - ttr, reftype); + permerror ("conversion from %qT to %qT discards qualifiers", + ttr, reftype); } return build_up_reference (reftype, expr, flags, decl); @@ -646,9 +646,9 @@ ocp_convert (tree type, tree expr, int convtype, int flags) || TREE_CODE (intype) == POINTER_TYPE)) { if (flags & LOOKUP_COMPLAIN) - pedwarn ("conversion from %q#T to %q#T", intype, type); + permerror ("conversion from %q#T to %q#T", intype, type); - if (flag_pedantic_errors) + if (!flag_permissive) return error_mark_node; } if (IS_AGGR_TYPE (intype)) @@ -892,8 +892,8 @@ convert_to_void (tree expr, const char *implicit) { /* [over.over] enumerates the places where we can take the address of an overloaded function, and this is not one of them. */ - pedwarn ("%s cannot resolve address of overloaded function", - implicit ? implicit : "void cast"); + error ("%s cannot resolve address of overloaded function", + implicit ? implicit : "void cast"); expr = void_zero_node; } else if (implicit && probe == expr && is_overloaded_fn (probe)) diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 99078e4..32a0db8 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -7028,12 +7028,7 @@ compute_array_index_type (tree name, tree size) { /* Check to see if the array bound overflowed. Make that an error, no matter how generous we're being. */ - int old_flag_pedantic_errors = flag_pedantic_errors; - int old_pedantic = pedantic; - pedantic = flag_pedantic_errors = 1; - constant_expression_warning (size); - pedantic = old_pedantic; - flag_pedantic_errors = old_flag_pedantic_errors; + constant_expression_error (size); /* An array must have a positive number of elements. */ if (INT_CST_LT (size, integer_zero_node)) diff --git a/gcc/cp/error.c b/gcc/cp/error.c index 0893f80..97a1785 100644 --- a/gcc/cp/error.c +++ b/gcc/cp/error.c @@ -2651,7 +2651,7 @@ cp_cpp_error (cpp_reader *pfile ATTRIBUTE_UNUSED, int level, dlevel = DK_WARNING; break; case CPP_DL_PEDWARN: - dlevel = pedantic_error_kind (); + dlevel = pedantic_warning_kind (); break; case CPP_DL_ERROR: dlevel = DK_ERROR; diff --git a/gcc/cp/lex.c b/gcc/cp/lex.c index 0b2a372..06c0bc2 100644 --- a/gcc/cp/lex.c +++ b/gcc/cp/lex.c @@ -647,16 +647,16 @@ unqualified_fn_lookup_error (tree name) Note that we have the exact wording of the following message in the manual (trouble.texi, node "Name lookup"), so they need to be kept in synch. */ - pedwarn ("there are no arguments to %qD that depend on a template " - "parameter, so a declaration of %qD must be available", - name, name); + permerror ("there are no arguments to %qD that depend on a template " + "parameter, so a declaration of %qD must be available", + name, name); if (!flag_permissive) { static bool hint; if (!hint) { - error ("(if you use %<-fpermissive%>, G++ will accept your " + inform ("(if you use %<-fpermissive%>, G++ will accept your " "code, but allowing the use of an undeclared name is " "deprecated)"); hint = true; diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 817a062..3ffac73 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -9775,7 +9775,7 @@ cp_parser_template_id (cp_parser *parser, } /* Otherwise, emit an error about the invalid digraph, but continue parsing because we got our argument list. */ - pedwarn ("%<<::%> cannot begin a template-argument list"); + permerror ("%<<::%> cannot begin a template-argument list"); inform ("%<<:%> is an alternate spelling for %<[%>. Insert whitespace " "between %<<%> and %<::%>"); if (!flag_permissive) diff --git a/gcc/diagnostic.c b/gcc/diagnostic.c index bc4e051..2988904 100644 --- a/gcc/diagnostic.c +++ b/gcc/diagnostic.c @@ -544,11 +544,31 @@ pedwarn (const char *gmsgid, ...) va_start (ap, gmsgid); diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location, - pedantic_error_kind ()); + pedantic_warning_kind ()); report_diagnostic (&diagnostic); va_end (ap); } +/* A "permissive" error: issues an error unless -fpermissive was given + on the command line, in which case it issues a warning. Use this + for things that really should be errors but we want to support + legacy code. */ + +void +permerror (const char *gmsgid, ...) +{ + diagnostic_info diagnostic; + va_list ap; + + va_start (ap, gmsgid); + diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location, + permissive_error_kind ()); + diagnostic.option_index = OPT_fpermissive; + report_diagnostic (&diagnostic); + va_end (ap); +} + + /* A hard error: the code is definitely ill-formed, and an object file will not be produced. */ void diff --git a/gcc/diagnostic.h b/gcc/diagnostic.h index 992c0c4..a249574 100644 --- a/gcc/diagnostic.h +++ b/gcc/diagnostic.h @@ -50,7 +50,8 @@ typedef struct diagnostic_info int option_index; } diagnostic_info; -#define pedantic_error_kind() (flag_pedantic_errors ? DK_ERROR : DK_WARNING) +#define pedantic_warning_kind() (flag_pedantic_errors ? DK_ERROR : DK_WARNING) +#define permissive_error_kind() (flag_permissive ? DK_WARNING : DK_ERROR) /* Forward declarations. */ diff --git a/gcc/flags.h b/gcc/flags.h index e204150..686691c 100644 --- a/gcc/flags.h +++ b/gcc/flags.h @@ -197,6 +197,10 @@ extern int flag_dump_unnumbered; extern int flag_pedantic_errors; +/* Nonzero means make permerror produce warnings instead of errors. */ + +extern int flag_permissive; + /* Nonzero if we are compiling code for a shared library, zero for executable. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 05b49db..b8c03ce 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2008-03-02 Manuel Lopez-Ibanez + + PR 24924 + * g++.dg/cpp/string-2.C: This is a warning now. + * g++.dg/cpp/pedantic-errors.C: -pedantic-errors is not enabled by + default, so add it. + 2008-03-01 Douglas Gregor * g++.dg/cpp0x/auto1.C: New. diff --git a/gcc/testsuite/g++.dg/cpp/pedantic-errors.C b/gcc/testsuite/g++.dg/cpp/pedantic-errors.C new file mode 100644 index 0000000..1684749 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp/pedantic-errors.C @@ -0,0 +1,5 @@ +/* { dg-do preprocess } */ +/* { dg-options "-std=c++98 -pedantic-errors" } */ + +#if 1 +#endif 1 /* { dg-error "error: extra tokens at end of #endif directive" } */ diff --git a/gcc/testsuite/g++.dg/cpp/string-2.C b/gcc/testsuite/g++.dg/cpp/string-2.C index b947c73..137c3de 100644 --- a/gcc/testsuite/g++.dg/cpp/string-2.C +++ b/gcc/testsuite/g++.dg/cpp/string-2.C @@ -1,7 +1,6 @@ -// Test diagnostics for interpreting strings: should be an error by -// default. +// Test diagnostics for interpreting strings: This is a pedwarn. // Origin: Joseph Myers // { dg-do compile } // { dg-options "" } -const char *s = "\q"; // { dg-error "error: unknown escape sequence" } +const char *s = "\q"; // { dg-warning "warning: unknown escape sequence" } diff --git a/gcc/toplev.c b/gcc/toplev.c index 5b1600c..58c19c5 100644 --- a/gcc/toplev.c +++ b/gcc/toplev.c @@ -281,6 +281,10 @@ enum tls_model flag_tls_default = TLS_MODEL_GLOBAL_DYNAMIC; int flag_pedantic_errors = 0; +/* Nonzero means make permerror produce warnings instead of errors. */ + +int flag_permissive = 0; + /* -dA causes debug commentary information to be produced in the generated assembly code (to make it more readable). This option is generally only of use to those who actually need to read the diff --git a/gcc/toplev.h b/gcc/toplev.h index 26a085d..45e4646 100644 --- a/gcc/toplev.h +++ b/gcc/toplev.h @@ -62,6 +62,7 @@ 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 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); -- 2.7.4