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.133.124]) by sourceware.org (Postfix) with ESMTP id 47EDF3858C56 for ; Tue, 22 Oct 2024 17:54:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 47EDF3858C56 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 47EDF3858C56 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729619699; cv=none; b=RpUDd0Z86FRKb+Q6F9FtdXoteITcc84F9txZunFXkYomhlQ5cOrTLdvsWSPw0OICVBq5POQ7/lDc1ucnar2cOPzizuyIdtJv6zBt78G1Dc9HBCITKNpFgR5ZLuV3VZnENbbHv6imrx7K78rzGRATMWJzRgeXRcm8QrjAQQ+6Zb4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729619699; c=relaxed/simple; bh=AekZ56KD+ioj03cCZt2z/AVWPp8wmXoZTcCl52+a+Go=; h=DKIM-Signature:From:Date:To:Subject:Message-ID:MIME-Version; b=GdsoYgKf0Y8J93YNegAZ6u3lSafnwCRMEljYaQdGhb/iSCp7Sjp9s082s6x2FTXMAZO7BsNitYQzZnNM0+1/UF6+5+S0QkvlYoalMJE+gHbbY80v0s5IJ5CqG54KtjMIo2yVGQPCR5IWBL0mO5c16a2NsV5W+0doyM/L9PyAbgg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729619697; 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: in-reply-to:in-reply-to:references:references; bh=thMbbugSsJNVz1t0LH2hZ6qVg3r66kPwlJQ2d5UOJ+o=; b=Xhxs4CcYeLsnItgGT7glgiV5741WvX9SIeta+u4PnzQ2x+PWctFIWCURANhwMdIzv0WBFz AKgOWYZAYIRCGcYRRtyuL1vOJBa7ZZD5sjogVZpvAMks80oetVivRHB3nZNntZPzfeqOXc 2Bs7JbuU0V49wLEMV5TXA8SYoMa1lk0= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-28-kZy7puDDOAaSb_GIU74NvQ-1; Tue, 22 Oct 2024 13:54:52 -0400 X-MC-Unique: kZy7puDDOAaSb_GIU74NvQ-1 Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-6cbf4770c18so18047996d6.2 for ; Tue, 22 Oct 2024 10:54:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729619692; x=1730224492; h=mime-version:references:message-id:in-reply-to:subject:cc:to:date :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=thMbbugSsJNVz1t0LH2hZ6qVg3r66kPwlJQ2d5UOJ+o=; b=sUkp0pjOWSim3/b9EhQV014bIaybNSN/G+qdum0EyBGvcUt7BgrSv0jKYEtZ5THq3G cfKaCBAA7yhD38fKE1Rmx/ZVcjLyU9UBXu94oWv5ZVWHgNOctYxvXAysNqrTkwJVAq0f II9h8cXm2wKALIaDuoSCmFR8ZNUjU6Wjl/8zeC82lzwdLkFApgVr48M0IIoEdwAK/bhI F6Qjiy7LvVto6dcanm4Hil3Bjiud06wN1j/EOElTyAX6Z1bWjAGyV58H4ZyJ+F1g0SAT gZ/BJsJOEKdkZISXMnAbDdB+xmmJvJVUmdgI72PVWiHfks30QTdOauSce+macg0QmXbC QixA== X-Forwarded-Encrypted: i=1; AJvYcCUZop1GEV18WULdrpRS5nKpYW3P/nkWiVb2/GsKg/qyKp/48MCVbiOGiSLziwluWg5zU5kM2tgmSbhOsw==@gcc.gnu.org X-Gm-Message-State: AOJu0YzhPgdy9XThljkdSeTZGmUPt/SOUBjDlLjwtbRkeNpWEP7ixOg6 u3Lp5kcFeix7L6d8f8pGei9HkbBnZQlVY2wBzAPXZWvrzp9evuY2Mdz7VWK8cEHPLqL9N8PBVwy AqD9kqVMFdmIYMEDzLD9xeROc39mhnGmYWF4sixWG7NEVKo9yl2BwwEg= X-Received: by 2002:a05:6214:3014:b0:6cc:17f7:3837 with SMTP id 6a1803df08f44-6cde152f990mr106302946d6.5.1729619692298; Tue, 22 Oct 2024 10:54:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHM2lDSLZ/tIcMqbbCfORhabJZNCG9bHOv6AysAw5JzfqKTlipM4r2SbHTmDdHrM2MqSrnTbA== X-Received: by 2002:a05:6214:3014:b0:6cc:17f7:3837 with SMTP id 6a1803df08f44-6cde152f990mr106302866d6.5.1729619691931; Tue, 22 Oct 2024 10:54:51 -0700 (PDT) Received: from [192.168.1.130] (ool-18bb2a2e.dyn.optonline.net. [24.187.42.46]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6ce009e4e0fsm31037256d6.123.2024.10.22.10.54.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Oct 2024 10:54:51 -0700 (PDT) From: Patrick Palka X-Google-Original-From: Patrick Palka Date: Tue, 22 Oct 2024 13:54:50 -0400 (EDT) To: Jason Merrill cc: Patrick Palka , gcc-patches@gcc.gnu.org Subject: Re: [PATCH] c++: reference variable as default targ [PR101463] In-Reply-To: Message-ID: <5c30b275-c9d3-bbad-07aa-754dc12e355d@idea> References: <20240105200116.1382389-1-ppalka@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-13.8 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_H3,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 List-Id: On Tue, 9 Jan 2024, Jason Merrill wrote: > On 1/5/24 15:01, Patrick Palka wrote: > > Bootstrapped and regtested on x86_64-pc-linux-gnu, does this > > look OK for trunk? > > > > -- >8 -- > > > > Here during default template argument substitution we wrongly consider > > the (substituted) default arguments v and vt as value-dependent[1] > > which ultimately leads to deduction failure for the calls. > > > > The bogus value_dependent_expression_p result aside, I noticed > > type_unification_real during default targ substitution keeps track of > > whether all previous targs are known and non-dependent, as is the case > > for these calls. And in such cases it should be safe to avoid checking > > dependence of the substituted default targ and just assume it's not. > > This patch implements this optimization, which lets us accept both > > testcases by sidestepping the value_dependent_expression_p issue > > altogether. > > Hmm, maybe instead of substituting and asking if it's dependent, we should > specifically look for undeduced parameters. We took this approach with r15-3038-g5348e3cb9bc99d for GCC 15, but it might be too risky to backport. The original approach of avoiding the dependence check when we know all previous arguments are non-dependent seems safer, and we can simplify it a bit even. What do you think about backporting the following in order to fix 101463 on the release branches? Bootstrappped and regtested on x86_64-pc-linux-gnu on the 14 branch. -- >8 -- Subject: [PATCH] c++: reference variable as default targ [PR101463] Here during default template argument substitution we wrongly consider the (substituted) default arguments v and vt as value-dependent[1] which ultimately leads to deduction failure for the calls. The bogus value_dependent_expression_p result aside, I noticed type_unification_real during default targ substitution keeps track of whether all previous targs are known and non-dependent, as is the case for these calls. And in such cases it should be safe to avoid checking dependence of the substituted default targ and just assume it's not. This patch implements this optimization, which lets us accept both testcases by sidestepping the value_dependent_expression_p issue altogether. Note that for GCC 15 we fixed this differently, see r15-3038-g5348e3cb9bc99d. PR c++/101463 gcc/cp/ChangeLog: * pt.cc (type_unification_real): Avoid checking dependence of a substituted default template argument if we can assume it's non-dependent. gcc/testsuite/ChangeLog: * g++.dg/cpp1z/nontype6.C: New test. * g++.dg/cpp1z/nontype6a.C: New test. --- gcc/cp/pt.cc | 4 +++- gcc/testsuite/g++.dg/cpp1z/nontype6.C | 24 ++++++++++++++++++++++++ gcc/testsuite/g++.dg/cpp1z/nontype6a.C | 25 +++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp1z/nontype6.C create mode 100644 gcc/testsuite/g++.dg/cpp1z/nontype6a.C diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 818d5b65edc..4f83426fb56 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -23651,12 +23651,14 @@ type_unification_real (tree tparms, /* We replaced all the tparms, substitute again out of template context. */ substed = NULL_TREE; + else + processing_template_decl = 1; } if (!substed) substed = tsubst_template_arg (arg, full_targs, complain, NULL_TREE); - if (!uses_template_parms (substed)) + if (!processing_template_decl || !uses_template_parms (substed)) arg = convert_template_argument (parm, substed, full_targs, complain, i, NULL_TREE); else if (saw_undeduced == 1) diff --git a/gcc/testsuite/g++.dg/cpp1z/nontype6.C b/gcc/testsuite/g++.dg/cpp1z/nontype6.C new file mode 100644 index 00000000000..06cd234cc61 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/nontype6.C @@ -0,0 +1,24 @@ +// PR c++/101463 +// { dg-do compile { target c++17 } } + +int a; + +int& v = a; + +template +void f(int) { } + +template +void g(T) { } + +template +int& vt = a; + +template> +void h(T) { } + +int main() { + f(0); + g(0); + h(0); +} diff --git a/gcc/testsuite/g++.dg/cpp1z/nontype6a.C b/gcc/testsuite/g++.dg/cpp1z/nontype6a.C new file mode 100644 index 00000000000..8bc40a0505c --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/nontype6a.C @@ -0,0 +1,25 @@ +// PR c++/101463 +// A version of nontype6.C where v and vt are constexpr. +// { dg-do compile { target c++17 } } + +int a; + +constexpr int& v = a; + +template +void f(int) { } + +template +void g(T) { } + +template +constexpr int& vt = a; + +template> +void h(T) { } + +int main() { + f(0); + g(0); + h(0); +} -- 2.47.0.107.g34b6ce9b30