C++ ObjC++ Var(warn_catch_value) Warning Joined RejectNegative UInteger LangEnabledBy(C++ ObjC++,Wall, 1, 0) IntegerRange(0, 3)
Warn about catch handlers of non-reference type.
+Wchanges-meaning
+C++ ObjC++ Var(warn_changes_meaning) Warning Init(1)
+Complain about a name being declared as a class member after a previous use of the same name.
+
Wchar-subscripts
C ObjC C++ ObjC++ Var(warn_char_subscripts) Warning LangEnabledBy(C ObjC C++ ObjC++,Wall)
Warn about subscripts whose type is \"char\".
return;
/* The C language allows members to be declared with a type of the same
name, and the C++ standard says this diagnostic is not required. So
- allow it in extern "C" blocks unless predantic is specified.
+ allow it in extern "C" blocks unless pedantic is specified.
Allow it in all cases if -ms-extensions is specified. */
if ((!pedantic && current_lang_name == lang_name_c)
|| flag_ms_extensions)
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. */
- if (permerror (location_of (decl),
- "declaration of %q#D changes meaning of %qD",
- decl, OVL_NAME (decl)))
+ auto ov = make_temp_override (global_dc->pedantic_errors);
+ if (TREE_CODE (decl) == TYPE_DECL
+ && TREE_CODE (olddecl) == TYPE_DECL
+ && same_type_p (TREE_TYPE (decl), TREE_TYPE (olddecl)))
+ /* Different declaration, but same meaning; just warn. */;
+ else if (flag_permissive)
+ /* Let -fpermissive make it a warning like past versions. */;
+ else
+ /* Make it an error. */
+ global_dc->pedantic_errors = 1;
+ if (pedwarn (location_of (decl), OPT_Wchanges_meaning,
+ "declaration of %q#D changes meaning of %qD",
+ decl, OVL_NAME (decl)))
{
inform (loc, "used here to mean %q#D", olddecl);
inform (location_of (olddecl), "declared here" );
@end itemize
+@item -Wno-changes-meaning @r{(C++ and Objective-C++ only)}
+C++ requires that unqualified uses of a name within a class have the
+same meaning in the complete scope of the class, so declaring the name
+after using it is ill-formed:
+@smallexample
+struct A;
+struct B1 @{ A a; typedef A A; @}; // warning, 'A' changes meaning
+struct B2 @{ A a; struct A @{ @}; @}; // error, 'A' changes meaning
+@end smallexample
+By default, the B1 case is only a warning because the two declarations
+have the same type, while the B2 case is an error. Both diagnostics
+can be disabled with @option{-Wno-changes-meaning}. Alternately, the
+error case can be reduced to a warning with
+@option{-Wno-error=changes-meaning} or @option{-fpermissive}.
+
+Both diagnostics are also suppressed by @option{-fms-extensions}.
+
@item -Wchar-subscripts
@opindex Wchar-subscripts
@opindex Wno-char-subscripts