From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1666) id 57BE13858C50; Mon, 24 Oct 2022 08:50:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 57BE13858C50 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666601446; bh=b0NPxiJUWfgd0azifjCZLeVhizm1Pjt4j7LiX82bn8M=; h=From:To:Subject:Date:From; b=qc4Qz0gXoJiwrtXmqJXV9x9MvDPoAXfU1vIdcQEnCHWaA07NJZkwx8XNWKM5l5bEi ZL5KZTSKVWYQiXOlYuvqzFdxOGSl2W7eKpPnWZUrhRSMZtfgjXjquDt/ZeIfry6r0T SgPDPffoFfF3nfzPEhqgXxWzUv1Tbtr4ysYhtSRQ= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Richard Biener To: gcc-cvs@gcc.gnu.org Subject: [gcc r11-10332] c++: Fix ICE with -Wmismatched-tags [PR105725] X-Act-Checkin: gcc X-Git-Author: Marek Polacek X-Git-Refname: refs/heads/releases/gcc-11 X-Git-Oldrev: 9e7011b858749b0c735a52bf38b9cfb1d53458bf X-Git-Newrev: bd0c76a2329e7fe6d6612c2259647bbb67f5866a Message-Id: <20221024085046.57BE13858C50@sourceware.org> Date: Mon, 24 Oct 2022 08:50:42 +0000 (GMT) List-Id: https://gcc.gnu.org/g:bd0c76a2329e7fe6d6612c2259647bbb67f5866a commit r11-10332-gbd0c76a2329e7fe6d6612c2259647bbb67f5866a Author: Marek Polacek Date: Fri May 27 10:51:30 2022 -0400 c++: Fix ICE with -Wmismatched-tags [PR105725] Here we ICE with -Wmismatched-tags on something like template bool B>>; Specifically, the "class T::foo" bit. There, class_decl_loc_t::add gets a TYPENAME_TYPE as TYPE, rather than a class/union type, so checking TYPE_BEING_DEFINED will crash. I think it's OK to allow a TYPENAME_TYPE to slip into that function; we just shouldn't consider the 'class' tag redundant (which works as a 'typename'). In fact, every other compiler *requires* it. PR c++/105725 gcc/cp/ChangeLog: * parser.c (class_decl_loc_t::add): Check CLASS_TYPE_P. gcc/testsuite/ChangeLog: * g++.dg/warn/Wmismatched-tags-10.C: New test. (cherry picked from commit d822f4bbd714c6595f70cc68888dcebecfb6662d) Diff: --- gcc/cp/parser.c | 5 +++-- gcc/testsuite/g++.dg/warn/Wmismatched-tags-10.C | 10 ++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 94b10922b90..ead4a239cc3 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -32326,7 +32326,8 @@ class_decl_loc_t::add (cp_parser *parser, location_t key_loc, bool key_redundant = (!def_p && !decl_p && (decl == type_decl || TREE_CODE (decl) == TEMPLATE_DECL - || TYPE_BEING_DEFINED (type))); + || (CLASS_TYPE_P (type) + && TYPE_BEING_DEFINED (type)))); if (key_redundant && class_key != class_type @@ -32364,7 +32365,7 @@ class_decl_loc_t::add (cp_parser *parser, location_t key_loc, } else { - /* TYPE was previously defined in some unknown precompiled hdeader. + /* TYPE was previously defined in some unknown precompiled header. Simply add a record of its definition at an unknown location and proceed below to add a reference to it at the current location. (Declarations in precompiled headers that are not definitions diff --git a/gcc/testsuite/g++.dg/warn/Wmismatched-tags-10.C b/gcc/testsuite/g++.dg/warn/Wmismatched-tags-10.C new file mode 100644 index 00000000000..d7e10743bb4 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wmismatched-tags-10.C @@ -0,0 +1,10 @@ +// PR c++/105725 +// { dg-do compile { target c++14 } } +// { dg-options "-Wall -Wmismatched-tags" } + +template struct enable_if; +template using enable_if_t = typename enable_if::type; +template bool is_class_v; +template bool B; +template +bool B>>;