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.
This commit is contained in:
Martin Sebor 2021-12-16 15:11:45 -07:00
parent f91814c225
commit 93faac7e32
2 changed files with 33 additions and 1 deletions

View file

@ -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

View file

@ -0,0 +1,32 @@
/* PR c++/103703 - ICE with -Wmismatched-tags with friends and templates
{ dg-do compile }
{ dg-options "-Wall -Wmismatched-tags" } */
template <typename T>
struct A
{
struct B { };
};
template <typename T>
struct C
{
friend class A<C>::B; // { dg-warning "-Wmismatched-tags" "pr102036" { xfail *-*-* } }
};
template struct C<int>;
template <typename T>
struct D
{
friend class A<D>::B; // okay, specialized as class below
};
template <>
struct A<long>
{
class B { };
};
template struct D<long>;