From patchwork Tue Dec 14 22:28:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Sebor X-Patchwork-Id: 1567889 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=EEs6dreC; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JDCjQ71xkz9s3q for ; Wed, 15 Dec 2021 09:29:30 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CC3853857C69 for ; Tue, 14 Dec 2021 22:29:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CC3853857C69 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1639520968; bh=KtT6+LWAShdsvHRQg9BbFDf7G4zlBPIf3898aKewC5o=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=EEs6dreCniSXrNUpe9+uJ1lOYqteOHjwtAWqaegJzLAtWbMKxuj9aCZJ6pcGU1kWE eOCx04MuZWiJAxtd8wz0LEZ0fVzj7KZntgKqa43YZt8VeDn3z2twITSaF8Qld1IWw0 w629qnQ+/ScibsaJt2G5WnaK9MOg8w23sHZaj2qI= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-oi1-x22c.google.com (mail-oi1-x22c.google.com [IPv6:2607:f8b0:4864:20::22c]) by sourceware.org (Postfix) with ESMTPS id DDA483858428 for ; Tue, 14 Dec 2021 22:28:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DDA483858428 Received: by mail-oi1-x22c.google.com with SMTP id bk14so29152379oib.7 for ; Tue, 14 Dec 2021 14:28:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-language; bh=KtT6+LWAShdsvHRQg9BbFDf7G4zlBPIf3898aKewC5o=; b=MREd/a4YbgShbYvdihfJT5eDcVuDzobIVVtspGmJ+QBvRCThw47YqKc6mLrew3hKzM jGs+zE4d+74dKjj7AkQgs0hTbvB10cLUSLAPtQ+NcbKgUjNuJZvJtkEvkcOcN/u27waF PkY2FkLOuE2yiuiU7qSW8gJC5oyPysFRULadpp4zHrX3MVhobqhRBsSyFQOV+DhERHUq dcPyHXerB2cRxSM/Sml6zW9gVpcKMQgOCsXjMCzmZdh183jE9bcgeyCkzlDHghP3ykUu OtAipGfOk56F2/dh+X+pjOQe4If+sGISt5mwBeGxTRqeRzLxS4xhB4/TE8nAkUr97Xoi dwDQ== X-Gm-Message-State: AOAM531iqnp655h7tOLaV28BYtiup8agyGeDYw54bXnIixqHAsPe+ZMy ocP+lO5mPz/g/tu7r7sMvyA= X-Google-Smtp-Source: ABdhPJxEQDjVVc69LdMeiBEylk44h9+fuFpJLobWnRUO67tqkOvA1j31y+hK13mqoVHVNNaDDc/ljA== X-Received: by 2002:a05:6808:3ab:: with SMTP id n11mr35245744oie.145.1639520933285; Tue, 14 Dec 2021 14:28:53 -0800 (PST) Received: from [192.168.0.41] (184-96-227-137.hlrn.qwest.net. [184.96.227.137]) by smtp.gmail.com with ESMTPSA id d6sm24547otb.4.2021.12.14.14.28.52 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 14 Dec 2021 14:28:52 -0800 (PST) To: gcc-patches , Jason Merrill Subject: [PATCH] Check for class type before assuming a type is one [PR103703] Message-ID: <6ccecbc4-a646-0bfb-7891-7804e03d2b1a@gmail.com> Date: Tue, 14 Dec 2021 15:28:51 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 Content-Language: en-US X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Martin Sebor via Gcc-patches From: Martin Sebor Reply-To: Martin Sebor Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" The attached patch avoids an ICE when using the CLASSTYPE_IMPLICIT_INSTANTIATION() macro with an argument that is not a class type but rather a typename_type. The test case should trigger a warning but doesn't because the code doesn't fully handle explicit instantiations. Martin 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): 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 52225d46d4e..d21e1d9de6d 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -33536,7 +33536,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;