From patchwork Mon Mar 28 13:29:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1610160 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=DtTz/rd/; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4KRtqN3j12z9sDX for ; Tue, 29 Mar 2022 00:30:24 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9B6183857815 for ; Mon, 28 Mar 2022 13:30:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9B6183857815 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1648474220; bh=MzrAZIE4hKWbIS8IhzgIgSuv1263sI1Pc5Y+qj82UFI=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=DtTz/rd/JrRid8yiRoh+QM/elGCKp+2fFGiQl4/kOMwYQIdiX8EYBzMgISgbMOWKI w3/WHse6gnJ13os0wKt3+Oroipu8AiDfxIyVnPCNkG8fHtVfuBIUzzwnbOD4vWeW/+ 39HvCwP5K+qVY0GmCINkfP088u1aA4sq9SaYGQ9o= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 09BE2385782C for ; Mon, 28 Mar 2022 13:29:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 09BE2385782C Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-257-MvceelG8OBaPk41vd1MDog-1; Mon, 28 Mar 2022 09:29:07 -0400 X-MC-Unique: MvceelG8OBaPk41vd1MDog-1 Received: by mail-qt1-f198.google.com with SMTP id y23-20020ac85257000000b002e06697f2ebso12164837qtn.16 for ; Mon, 28 Mar 2022 06:29:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=MzrAZIE4hKWbIS8IhzgIgSuv1263sI1Pc5Y+qj82UFI=; b=sT7NFtZQJFHq2veihMds6ln5ZvqNRVrdvL7KqW+LmmgLhiNkKK0+BdtIMtqgacnQs+ 4RARfuX2OWbuPIBoWKS0/qWTmsLoiLIa5ennxjCALg0/Qs1harl6Op3GWkNoxyrPe13L MyhCav7tj0vLyqxDYnv1NHXFTyOcvcv2cCFvLRKSMcT0YuMCHx6WmR3aYl5NKT5sSCu8 lDvtwfkLmzQesIbN40hkzmytbNbDQ4Y8R5u2Gskj54QoQ+sBY/I5rv96y2Xchf5upY61 jEbLw5MiAbkIWr7L36Hpvw5Phn8nKABmC0zPhdHIOx3bpKr90FnFcYmPsZ4Fh6BbRmOP XuNg== X-Gm-Message-State: AOAM532rTqoCkqe0wZSSsOlCM4QdUJDs+Qe4UIAiDi5JiTbV3NdykVaG 3Ns0exuIfOMx2c8CymvE8R0s+c4ZnT4CuL+IzwoacKHwhPhVneyxb7szUwAGReoHvNaLB86twvk ZC7gEyNReydVVjBpsETJuC4L9Jc8QWdemepievB/gd+A6o2+lXdXbJkz/vKze73XLXvY= X-Received: by 2002:a05:622a:120a:b0:2e1:e23e:6199 with SMTP id y10-20020a05622a120a00b002e1e23e6199mr21952857qtx.195.1648474147146; Mon, 28 Mar 2022 06:29:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyDoCVXbfWsN8ugJsm3yw2DOqU0mzrAVf4aBj2l4FAuEV9oR5+M8N4CqBiTukzF5axThn9VDA== X-Received: by 2002:a05:622a:120a:b0:2e1:e23e:6199 with SMTP id y10-20020a05622a120a00b002e1e23e6199mr21952831qtx.195.1648474146871; Mon, 28 Mar 2022 06:29:06 -0700 (PDT) Received: from localhost.localdomain (ool-18e40894.dyn.optonline.net. [24.228.8.148]) by smtp.gmail.com with ESMTPSA id t7-20020a05622a180700b002e0ccf0aa49sm13093642qtc.62.2022.03.28.06.29.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Mar 2022 06:29:06 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: ICE during constrained template friend matching [PR105064] Date: Mon, 28 Mar 2022 09:29:04 -0400 Message-Id: <20220328132904.4071925-1-ppalka@redhat.com> X-Mailer: git-send-email 2.35.1.677.gabf474a5dd MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-14.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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: Patrick Palka via Gcc-patches From: Patrick Palka Reply-To: Patrick Palka Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Here during declaration matching for the two constrained template friends, we crash from maybe_substitute_reqs_for because the second friend doesn't yet have DECL_TEMPLATE_INFO set (we're being called indirectly from push_template_decl). As far as I can tell, this situation happens only when declaring a constrained template friend within a non-template class (as in the testcase), in which case the substitution would be a no-op anyway, so it should be safe to just skip it. To that end this patch rearranges maybe_substitute_reqs_for to gracefully handle DECL_TEMPLATE_INFO being empty. Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk/11? PR c++/105064 gcc/cp/ChangeLog: * constraint.cc (maybe_substitute_reqs_for): Don't assume DECL_TEMPLATE_INFO is set. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/concepts-friend9.C: New test. --- gcc/cp/constraint.cc | 13 ++++--------- gcc/testsuite/g++.dg/cpp2a/concepts-friend9.C | 12 ++++++++++++ 2 files changed, 16 insertions(+), 9 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-friend9.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index e14578b1721..c5a991b9e71 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -1268,20 +1268,15 @@ remove_constraints (tree t) for declaration matching. */ tree -maybe_substitute_reqs_for (tree reqs, const_tree decl_) +maybe_substitute_reqs_for (tree reqs, const_tree decl) { if (reqs == NULL_TREE) return NULL_TREE; - tree decl = CONST_CAST_TREE (decl_); - tree result = STRIP_TEMPLATE (decl); - - if (DECL_UNIQUE_FRIEND_P (result)) + decl = STRIP_TEMPLATE (decl); + if (DECL_UNIQUE_FRIEND_P (decl) && DECL_TEMPLATE_INFO (decl)) { - tree tmpl = decl; - if (TREE_CODE (decl) != TEMPLATE_DECL) - tmpl = DECL_TI_TEMPLATE (result); - + tree tmpl = DECL_TI_TEMPLATE (decl); tree gargs = generic_targs_for (tmpl); processing_template_decl_sentinel s; if (uses_template_parms (gargs)) diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-friend9.C b/gcc/testsuite/g++.dg/cpp2a/concepts-friend9.C new file mode 100644 index 00000000000..09054d23d5d --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-friend9.C @@ -0,0 +1,12 @@ +// PR c++/105064 +// { dg-do compile { target c++20 } } + +struct A { + template + friend void f(T) requires true; +}; + +struct B { + template + friend void f(T) requires true; +};