From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 1E8A2388206F for ; Thu, 13 Jun 2024 15:28:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1E8A2388206F 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 1E8A2388206F 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=1718292528; cv=none; b=owF2hSX5SV98uL/P6R8WqIBnQZ5t45aVWyYQstVJ1v8Z/v8dcbBd3/a1ocrr4BWMvtU3HAkri4bH/93hEFLfWNz6uPMa0PtWQP5jB4p+VGYBBsWWX7+2GuELn7F7xWV6PLUD+h8Uc/juyoPSudC5MLcU+mbAWMJKkPzoZTVDcW8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718292528; c=relaxed/simple; bh=wKnoSUs5BkVi2DaM8sKU6ew/FzTqnK/fBDtQLdd6TNI=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=jsIP52EGdxtNrP1pZxGI1+xQdHJsDkLvtiQmQZHq6LGIrXjl4AuCRr9ni2yEzYVzM5ZfcD2h15rDJSTWUedNw/9pkvc85VQkxaZmDhejO6fiIg4MEO3YbN8rGbE2cflPRJfXe3qaM7dThO6RfmSW1FOcTsICLudUqWNnMivlL+8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718292525; 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: in-reply-to:in-reply-to:references:references; bh=w28pDAmTdpTBw+LQsho1R27ZeF4h3CA4kLO+5SMLAPA=; b=YpCFCwUBiX8AQ39CBRriB8zAtWr4Jf/IbyzWqFitpPyLS2fXgIZ4yhQFmIJpq0A1acXh/1 zUU3pEXKfgg9D7HG3IFL/VzHDceS2ma3rfalD7Aa1btK3Xl9HGZ6l2sd1sP7D7E+dc6Jww 0xQ/BFSUXD5lFK2bn0KVTG2m6d/+HTc= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-41-gq5vg0xkPPSFO_TdX-C4lA-1; Thu, 13 Jun 2024 11:28:43 -0400 X-MC-Unique: gq5vg0xkPPSFO_TdX-C4lA-1 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-440a6f3631dso11670661cf.0 for ; Thu, 13 Jun 2024 08:28:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718292523; x=1718897323; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=w28pDAmTdpTBw+LQsho1R27ZeF4h3CA4kLO+5SMLAPA=; b=ATfDwurRCXm7IYYebw+qEuk0yrom4JL5dcuLPjhIJ66S20Qf7k7YXV5mgdyyvK4+6d buKgQz+td5Gn0sJCiqUI+ksvYzjT2WRdngEK+vWjK0ElMJoUYFatgJ4Pgta61k8u856s 87gjx0kiZzoKMu/4tjc7AE8JedvGvG34reHswSepbpoS8eZUBWeqjWvFjW7eXAWCh479 dwH52rO5NSqoW9jOHLSIMYotQUl1uTXY7Xmn7UlqkErlsLsVODvi5xJhUZvI635wAp1s 5G9bO5ljJ/wFIBgM5LIHRmyTi01u4MeZCr6ODojcLiRqUpc/qwPjb1PdoiUWannlCTFx 3BIA== X-Gm-Message-State: AOJu0YwTOBnnY7Rx2my0Lj6d3ZjT/X28va/6t7MxFFKILTsaj4fZziKj iQpla8ak/u96m+pHYmdO2SPqJvfom/SIqlbZlDTLYM89ei7ry2IwZLmnJPczb4oPWfor5bf7zRY bRUNnvYZIYLs6PP8XDFGOIlZ/UyLtvYAFX1V0pYb17Y9nei4/p/IgUDo= X-Received: by 2002:a05:622a:286:b0:441:78:4ddf with SMTP id d75a77b69052e-4415ac97a21mr61649181cf.51.1718292523101; Thu, 13 Jun 2024 08:28:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFMoAl1/0Tn0A0e3DNypo3rAwrXxWPYbcUwmSmaMwNogLuDwj3/B+/mmgazzCZhy4KTLcjwTg== X-Received: by 2002:a05:622a:286:b0:441:78:4ddf with SMTP id d75a77b69052e-4415ac97a21mr61648991cf.51.1718292522671; Thu, 13 Jun 2024 08:28:42 -0700 (PDT) Received: from [192.168.1.130] (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-441f2d88406sm7122101cf.56.2024.06.13.08.28.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 13 Jun 2024 08:28:35 -0700 (PDT) Message-ID: Date: Thu, 13 Jun 2024 11:28:31 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] c++: alias CTAD and copy deduction guide [PR115198] To: Patrick Palka Cc: gcc-patches@gcc.gnu.org References: <20240523180653.755621-1-ppalka@redhat.com> <720e4cad-2401-4208-a401-177a1c29b336@redhat.com> <35ad2db8-bafe-4772-96c3-7467ae27da9b@redhat.com> From: Jason Merrill In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,KAM_SHORT,RCVD_IN_DNSWL_NONE,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.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 6/13/24 11:05, Patrick Palka wrote: > On Thu, 23 May 2024, Jason Merrill wrote: > >> On 5/23/24 17:42, Patrick Palka wrote: >>> On Thu, 23 May 2024, Jason Merrill wrote: >>> >>>> On 5/23/24 14:06, Patrick Palka wrote: >>>>> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look >>>>> OK for trunk/14? >>>>> >>>>> -- >8 -- >>>>> >>>>> Here we're neglecting to update DECL_NAME during the alias CTAD guide >>>>> transformation, which causes copy_guide_p to return false for the >>>>> transformed copy deduction guide since DECL_NAME is still __dguide_C >>>>> with TREE_TYPE C but it should be __dguide_A with TREE_TYPE A >>>>> (equivalently C). This ultimately results in ambiguity during >>>>> overload resolution between the copy deduction guide vs copy ctor guide. >>>>> >>>>> This patch makes us update DECL_NAME of a transformed guide accordingly >>>>> during alias CTAD. This eventually needs to be done for inherited CTAD >>>>> too, but it's not clear what identifier to use there since it has to be >>>>> unique for each derived/base pair. For >>>>> >>>>> template struct A { ... }; >>>>> template struct B : A { using A::A; } >>>>> >>>>> at first glance it'd be reasonable to give inherited guides a name of >>>>> __dguide_B with TREE_TYPE A, but since that name is already >>>>> used B's own guides its TREE_TYPE is already B. >>>> >>>> Why can't it be the same __dguide_B with TREE_TYPE B? >>> >>> Ah because copy_guide_p relies on TREE_TYPE in order to recognize a copy >>> deduction guide, and with that TREE_TYPE it would still incorrectly >>> return false for an inherited copy deduction guide, e.g. >>> >>> A(A) -> A >>> >>> gets transformed into >>> >>> B(A) -> B >>> >>> and A != B so copy_guide_p returns false. >> >> Hmm, that seems correct; the transformed candidate is not the copy deduction >> guide for B. > > By https://eel.is/c++draft/over.match.class.deduct#3.4 it seems that a > class template can now have multiple copy deduction guides with inherited > CTAD: the derived class's own copy guide, along with the transformed copy > guides of its eligible base classes. Do we want to follow the standard > precisely here, or should we maybe restrict the copy-guideness propagation > to alias CTAD only? The latter, I think; it seems nonsensical to have multiple copy guides. Jason >>> But it just occurred to me that this TREE_TYPE clobbering of the >>> __dguide_foo identifier already happens if we have two class templates >>> with the same name in different namespaces, since the identifier >>> contains only the terminal name. Maybe this suggests that we should >>> use a tree flag to track whether a guide is the copy deduction guide >>> instead of setting TREE_TYPE of DECL_NAME? >> >> Good point. >> >> Jason >> >> >