aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorMartin Sebor <msebor@redhat.com>2020-02-20 14:31:38 -0700
committerMartin Sebor <msebor@redhat.com>2020-02-20 14:31:38 -0700
commit96cbc56ed96490c58a9800f3e7507758b6602777 (patch)
treefc3c8cafecf114fbdd5c822a94ba6d89f45c6bb5 /gcc
parent7004e09db1e2a940ed6ad7578187d47d7ea7c773 (diff)
downloadgcc-96cbc56ed96490c58a9800f3e7507758b6602777.zip
gcc-96cbc56ed96490c58a9800f3e7507758b6602777.tar.gz
gcc-96cbc56ed96490c58a9800f3e7507758b6602777.tar.bz2
PR c++/93801 - False -Wmismatched-tags upon redundant typename
gcc/cp/ChangeLog: PR c++/93801 * parser.c (cp_parser_check_class_key): Only handle true C++ class-keys. gcc/testsuite/ChangeLog: PR c++/93801 * g++.dg/warn/Wredundant-tags-3.C: New test.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog5
-rw-r--r--gcc/cp/parser.c7
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/warn/Wredundant-tags-3.C45
4 files changed, 62 insertions, 0 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 811e1be..fd60343 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,8 @@
+2020-02-20 Martin Sebor <msebor@redhat.com>
+
+ PR c++/93801
+ * parser.c (cp_parser_check_class_key): Only handle true C++ class-keys.
+
2020-02-20 Martin Liska <mliska@suse.cz>
PR translation/93841
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 4684134..ee534b5 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -30995,6 +30995,13 @@ cp_parser_check_class_key (cp_parser *parser, location_t key_loc,
tree decl = cp_parser_lookup_name_simple (parser, name, input_location);
pop_deferring_access_checks ();
+ /* Only consider the true class-keys below and ignore typename_type,
+ etc. that are not C++ class-keys. */
+ if (class_key != class_type
+ && class_key != record_type
+ && class_key != union_type)
+ return;
+
/* The class-key is redundant for uses of the CLASS_TYPE that are
neither definitions of it nor declarations, and for which name
lookup returns just the type itself. */
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index d6a153e..216bac9 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2020-02-20 Martin Sebor <msebor@redhat.com>
+
+ PR c++/93801
+ * g++.dg/warn/Wredundant-tags-3.C: New test.
+
2020-02-20 Uroš Bizjak <ubizjak@gmail.com>
PR target/93828
diff --git a/gcc/testsuite/g++.dg/warn/Wredundant-tags-3.C b/gcc/testsuite/g++.dg/warn/Wredundant-tags-3.C
new file mode 100644
index 0000000..7b30e94
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Wredundant-tags-3.C
@@ -0,0 +1,45 @@
+/* PR c++/93801 - False -Wmismatched-tags upon redundant typename
+ { dg-do compile }
+ { dg-options "-Wall -Wredundant-tags" } */
+
+namespace N
+{
+ class C { };
+ enum E { };
+ struct S { };
+ union U { };
+
+ template <int> class TC { };
+ template <int> struct TS { };
+ template <int> union TU { };
+}
+
+N::C c1;
+typename N::C c2; // { dg-bogus "-Wredundant-tags" }
+class N::C c3; // { dg-warning "-Wredundant-tags" }
+
+N::E e1;
+typename N::E e2; // { dg-bogus "-Wredundant-tags" }
+enum N::E e3; // { dg-warning "-Wredundant-tags" }
+
+N::S s1;
+typename N::S s2; // { dg-bogus "-Wredundant-tags" }
+struct N::S s3; // { dg-warning "-Wredundant-tags" }
+
+N::U u1;
+typename N::U u2; // { dg-bogus "-Wredundant-tags" }
+ // { dg-bogus "'class' tag used in naming 'union N::U" "pr93809" { xfail *-*-*} .-1 }
+union N::U u3; // { dg-warning "-Wredundant-tags" }
+
+
+typedef N::TC<0> TC0;
+typedef typename N::TC<0> TC0;
+typedef class N::TC<0> TC0; // { dg-warning "-Wredundant-tags" "pr93809" { xfail *-*-*} .-1 }
+
+typedef N::TS<0> TS0;
+typedef typename N::TS<0> TS0;
+typedef struct N::TS<0> TS0; // { dg-warning "-Wredundant-tags" "pr93809" { xfail *-*-*} .-1 }
+
+typedef N::TS<0> TS0;
+typedef typename N::TS<0> TS0;
+typedef struct N::TS<0> TS0; // { dg-warning "-Wredundant-tags" "pr93809" { xfail *-*-*} .-1 }