From patchwork Thu Jul 11 17:08:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1959464 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=DUtZUog7; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WKh5p3pJ5z1xqr for ; Fri, 12 Jul 2024 03:09:02 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 956C9387543C for ; Thu, 11 Jul 2024 17:09:00 +0000 (GMT) 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 886393858401 for ; Thu, 11 Jul 2024 17:08:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 886393858401 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 886393858401 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1720717718; cv=none; b=DbnS3N0FsElpm5EUFJpArMYY7L2dz+9oZd2hzLoyu6DCNq8YtAtUDCEa4NwSscKsri6FZgIa6am6lEZtetxIoviMQQfzsiqsbIjxfO9dHuPY/SIz9K4alaEzyqlagZ50sb943kOYRu7HAqnXLC+tuxt+2s+Wgr2f+vbNUAIMPqs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1720717718; c=relaxed/simple; bh=ZyjHYbR+/MhU/TWRNgIXJD5tOpkpEggTpOvoLKBWS7Q=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=KZLYmGxZIA+f4eLlgiTgyqjK2mXVYK9Ed1IoUfc8a49JYbuO3TMvW8zGw8jXezA6xNDhXzf9TWnSPHCdVs1MtCbgKQanQMsOx+VpLRFmS0Z3P6oQ/sRry12HFtyiKijJhIT3YOeBh9e+E7v4L3DfhP2hnI+8tGHjwaK1QuZEsnY= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720717716; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ttHXkdXNoQjgNhkl8/1XwnWljzamDXzX4kaes9J0GDg=; b=DUtZUog70sYhezsny6YmKFT4b/Ox6QMe7U3WFxoCyJVkqHJLkcVwjg8DR9k+7UoT5XJGsm 4/J+ia70c0fvmdSV/r76GYEjW4Ve3WGBeix3N7en2ArHOlY43C3KIAwRcjuI/G2k9NhFl8 a8C1gWZ/vBGOe5CnGApuX3akfVzodmY= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-615-r_WIWEyaOjSM_mR1FLY9cw-1; Thu, 11 Jul 2024 13:08:35 -0400 X-MC-Unique: r_WIWEyaOjSM_mR1FLY9cw-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-79f006f9f14so351550485a.0 for ; Thu, 11 Jul 2024 10:08:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720717713; x=1721322513; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ttHXkdXNoQjgNhkl8/1XwnWljzamDXzX4kaes9J0GDg=; b=b3PvwKk0AReLJUbBx396lerpnbWxKsR+Sa32lDgvWZ+6TH6w7BmhMPA9b+nL0UXqvc e0u5XQHCpUcQtqvK3Vs0mkodBeM0ifkKuDjg8AZkG3CSzJ91zk62V6dTzYoe8nBen2D2 wCVzqX9C2JoCIDGqNY0JYzGQ8RGbU5Qcfo33po4xLwPf3a2fg60BwoMYwW7M1Fo6o335 VlhO1UU7EAqPH3mi2deM5L7VPl73ytiZsUm+XMHcowipqQ1gQ73edOD3sb7y1mI7Xpau vzDMwqwgoQoucP1n8cIbod2xEG4pD3MqiEYQs2bYJODaIuwW0A8j21+Lev/ewLA8Nfel whSQ== X-Gm-Message-State: AOJu0YyeeW4PxKixqUVySZqZRFX+tQfQj/xKtbrBt2fb0svzOaeXqwq5 zfMbk7nSovcvAO4pu127vGy7VA/4kBQsmVfpAy3913lCAvXOiSpwdUG6jpkmU+6wuoOCJZUDNWD jvRbOCX2Za7SX1HHIhGA0Ux/qLVPa6bGafVL2ggCYEHbaS7ivh6jizF+3tXXn/iqafJWetvh7mb lvkC3Zdn7ZrB4H3FGEFP1e2ERyg2sjinRFXiCX X-Received: by 2002:ad4:5dcd:0:b0:6b5:e761:73ce with SMTP id 6a1803df08f44-6b754bd5923mr4292526d6.16.1720717712838; Thu, 11 Jul 2024 10:08:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFe12i3rRxASSWSFLYsSo6h1lOJSf2ar9/R/lRVZuUEXIZwAXvSwoM5kM6Js0D/7YCbEOV1vA== X-Received: by 2002:ad4:5dcd:0:b0:6b5:e761:73ce with SMTP id 6a1803df08f44-6b754bd5923mr4292076d6.16.1720717712229; Thu, 11 Jul 2024 10:08:32 -0700 (PDT) Received: from localhost.localdomain (ool-18bb2a2e.dyn.optonline.net. [24.187.42.46]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6b61ba74bdcsm27289866d6.97.2024.07.11.10.08.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jul 2024 10:08:31 -0700 (PDT) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] c++: constrained partial spec type context [PR111890] Date: Thu, 11 Jul 2024 13:08:30 -0400 Message-ID: <20240711170830.3558231-1-ppalka@redhat.com> X-Mailer: git-send-email 2.45.2.827.g557ae147e6 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.5 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_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk/14? -- >8 -- maybe_new_partial_specialization wasn't propagating TYPE_CONTEXT when creating a new class type corresponding to a constrained partial spec, which do_friend relies on via template_class_depth to distinguish a template friend from a non-template friend, and so in the below testcase we were incorrectly instantiating the non-template operator+ as if it were a template leading to an ICE. PR c++/111890 gcc/cp/ChangeLog: * pt.cc (maybe_new_partial_specialization): Propagate TYPE_CONTEXT to the newly created partial specialization. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/concepts-partial-spec15.C: New test. --- gcc/cp/pt.cc | 1 + .../g++.dg/cpp2a/concepts-partial-spec15.C | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-partial-spec15.C diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index a382dce8788..314b0be4f19 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -992,6 +992,7 @@ maybe_new_partial_specialization (tree& type) tree t = make_class_type (TREE_CODE (type)); CLASSTYPE_DECLARED_CLASS (t) = CLASSTYPE_DECLARED_CLASS (type); SET_TYPE_TEMPLATE_INFO (t, build_template_info (tmpl, args)); + TYPE_CONTEXT (t) = TYPE_CONTEXT (type); /* We only need a separate type node for storing the definition of this partial specialization; uses of S are unconstrained, so all are diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-partial-spec15.C b/gcc/testsuite/g++.dg/cpp2a/concepts-partial-spec15.C new file mode 100644 index 00000000000..ad01a390fef --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-partial-spec15.C @@ -0,0 +1,20 @@ +// PR c++/111890 +// { dg-do compile { target c++20 } } + +template +struct A { + template + struct B { }; + + template requires T::value + struct B { }; + + template requires (sizeof(T) == sizeof(int)) + struct B { + friend void operator+(B&, int) { } + }; +}; + +void f(A::B b) { + b + 0; +}