From: Martin Sebor Date: Thu, 16 Dec 2021 22:11:45 +0000 (-0700) Subject: Check for class type before assuming a type is one [PR103703]. X-Git-Tag: basepoints/gcc-13~2289 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=93faac7e32e4f9503c559f2a3e5a4732f5e9ea09;p=thirdparty%2Fgcc.git 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 --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 5d72201f87c7..9cf74357ac9e 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -33527,7 +33527,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 000000000000..2712c4de1f63 --- /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;