aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2023-01-31 12:56:56 -0500
committerJason Merrill <jason@redhat.com>2023-01-31 21:25:42 -0500
commite2f939d30f5b397011d1dc06370dd8196aceebda (patch)
tree6e307314c373f719439a51e93bd85680c9f69db1 /gcc/cp
parentd03ae4be2c6d48255b18bb35dc25e551bd3a3b9d (diff)
downloadgcc-e2f939d30f5b397011d1dc06370dd8196aceebda.zip
gcc-e2f939d30f5b397011d1dc06370dd8196aceebda.tar.gz
gcc-e2f939d30f5b397011d1dc06370dd8196aceebda.tar.bz2
c++: Add -Wno-changes-meaning
In recent years this error has been coming up more because other compilers don't diagnose it as consistently. So let's add a flag for it, and be more lenient about cases that aren't likely to cause bugs. gcc/ChangeLog: * doc/invoke.texi: Document -Wno-changes-meaning. gcc/c-family/ChangeLog: * c.opt: Add -Wno-changes-meaning. gcc/cp/ChangeLog: * class.cc (note_name_declared_in_class): Change from permerror to -Wchanges-meaning pedwarn, forcing -pedantic-errors for most cases. gcc/testsuite/ChangeLog: * g++.dg/warn/changes-meaning2.C: New test. * g++.dg/warn/changes-meaning3.C: New test.
Diffstat (limited to 'gcc/cp')
-rw-r--r--gcc/cp/class.cc18
1 files changed, 14 insertions, 4 deletions
diff --git a/gcc/cp/class.cc b/gcc/cp/class.cc
index 351de6c..a2aa667 100644
--- a/gcc/cp/class.cc
+++ b/gcc/cp/class.cc
@@ -9016,7 +9016,7 @@ note_name_declared_in_class (tree name, tree decl)
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)
@@ -9032,9 +9032,19 @@ 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. */
- 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" );