From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1930) id 64602385842E; Thu, 16 Dec 2021 22:37:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 64602385842E MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Martin Sebor To: gcc-cvs@gcc.gnu.org Subject: [gcc r11-9395] Check for class type before assuming a type is one [PR103703]. X-Act-Checkin: gcc X-Git-Author: Martin Sebor X-Git-Refname: refs/heads/releases/gcc-11 X-Git-Oldrev: 43d67e5e75627ad1f5ba2e983a730f37547ba9b7 X-Git-Newrev: 4f556312da96bf2db67b014612de86594d4ad003 Message-Id: <20211216223757.64602385842E@sourceware.org> Date: Thu, 16 Dec 2021 22:37:57 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 16 Dec 2021 22:37:57 -0000 https://gcc.gnu.org/g:4f556312da96bf2db67b014612de86594d4ad003 commit r11-9395-g4f556312da96bf2db67b014612de86594d4ad003 Author: Martin Sebor Date: Thu Dec 16 15:35:55 2021 -0700 Check for class type before assuming a type is one [PR103703]. Resolves: PR c++/103703 - ICE with -Wmismatched-tags with friends and templates gcc/cp/ChangeLog: PR c++/103703 * parser.c (class_decl_loc_t::diag_mismatched_tags): Check for class type before assuming a type is one. gcc/testsuite/ChangeLog: PR c++/103703 * g++.dg/warn/Wmismatched-tags-9.C: New test. Diff: --- gcc/cp/parser.c | 2 +- gcc/testsuite/g++.dg/warn/Wmismatched-tags-9.C | 32 ++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index af10caa48be..01006989a02 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -32437,7 +32437,7 @@ class_decl_loc_t::diag_mismatched_tags (tree type_decl) class_decl_loc_t *cdlguide = this; tree type = TREE_TYPE (type_decl); - if (CLASSTYPE_IMPLICIT_INSTANTIATION (type)) + if (CLASS_TYPE_P (type) && CLASSTYPE_IMPLICIT_INSTANTIATION (type)) { /* For implicit instantiations of a primary template look up the primary or partial specialization and use it as diff --git a/gcc/testsuite/g++.dg/warn/Wmismatched-tags-9.C b/gcc/testsuite/g++.dg/warn/Wmismatched-tags-9.C new file mode 100644 index 00000000000..2712c4de1f6 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wmismatched-tags-9.C @@ -0,0 +1,32 @@ +/* PR c++/103703 - ICE with -Wmismatched-tags with friends and templates + { dg-do compile } + { dg-options "-Wall -Wmismatched-tags" } */ + +template +struct A +{ + struct B { }; +}; + +template +struct C +{ + friend class A::B; // { dg-warning "-Wmismatched-tags" "pr102036" { xfail *-*-* } } +}; + +template struct C; + + +template +struct D +{ + friend class A::B; // okay, specialized as class below +}; + +template <> +struct A +{ + class B { }; +}; + +template struct D;