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 851D13858D3C for ; Mon, 27 Mar 2023 17:54:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 851D13858D3C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1679939675; 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=g2Aipm3h5vPHAa8XHVIqh6VHBhD8qv6Dip6A6pHNClA=; b=VwXWHfeZ7rBxfzXvAFPpMQcWGc2QE20tS/12fDyksfVIbMo8GiHz+1YGsfTpBHfjoDOtTK MORq7VvzZNsrzNYZPFPcCQnoE+BU/iEwwRbb9JljRNg9+l/rjGa7kdyAIK+KEYgzuntQBF 5OuTIpYRNHlUZ38m63RjKylq4fTiOpA= Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-263-6jiXqWRtMRaRj8BaZFzBfA-1; Mon, 27 Mar 2023 13:54:33 -0400 X-MC-Unique: 6jiXqWRtMRaRj8BaZFzBfA-1 Received: by mail-ed1-f72.google.com with SMTP id p36-20020a056402502400b004bb926a3d54so13649408eda.2 for ; Mon, 27 Mar 2023 10:54:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679939672; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=g2Aipm3h5vPHAa8XHVIqh6VHBhD8qv6Dip6A6pHNClA=; b=XvIEIcTkjBdJpJDZDEGS7pHd17mNfUxg+s7rV/pWWNeMnqP69BFvmpndjaaEX4+9Y2 BiWfs2iwWHXcJxEOTjwbdFJtY4SqD/OBcCn5cdlHPpj70kasIejnIBDx6so+aldKY30c 1SyDzAibCKpjP8ziL0wcBOAE2hpyhsnMzonvi9jLpNF+ifOiqGqUpxfVfuHeJszGgUS3 Rdk6m7df65SXEw+6fKJQkUjyK1KCaytCBp09qW/nBcZv74KvoDQ8IE3WH7GDR70Prtdl 9t4rYU8t5m9hWIj7z9FgK+WLKhg5CLThYIOVuDYNzb0zUad7iWuv41uWnL1ZPuWMzeIl 70OA== X-Gm-Message-State: AAQBX9eUjCWvhyYzxlHEuWXu4Q+8/UG9aTqyqQnvMWRrRfdcRMPvjB29 QGKVwFQ/I9croeuBQSHslr6YC5WBCCqXThHccOjb49T5FAc7Yh7W1frAc5Tax0HFjtYbL1ZVJcz YztQw5VaRCKOfbKHOvzc3n9R8SPwTdlYBEkKFrgJzdg== X-Received: by 2002:a17:906:2f02:b0:8b1:780d:e43d with SMTP id v2-20020a1709062f0200b008b1780de43dmr6412757eji.13.1679939672105; Mon, 27 Mar 2023 10:54:32 -0700 (PDT) X-Google-Smtp-Source: AKy350aa07nKn7Ivw0MqAiVQeYUMQzIB6sZDggYfd5flTqqv4mqrtuh211mAABuQdydDsB4OsV9PSvE0N8YrlTf6UHQ= X-Received: by 2002:a17:906:2f02:b0:8b1:780d:e43d with SMTP id v2-20020a1709062f0200b008b1780de43dmr6412751eji.13.1679939671827; Mon, 27 Mar 2023 10:54:31 -0700 (PDT) MIME-Version: 1.0 References: <20230317152629.3944138-1-ppalka@redhat.com> In-Reply-To: <20230317152629.3944138-1-ppalka@redhat.com> From: Patrick Palka Date: Mon, 27 Mar 2023 13:54:20 -0400 Message-ID: Subject: Re: [PATCH] c++: NTTP constraint depending on outer args [PR109160] To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-12.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_H2,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 Fri, Mar 17, 2023 at 11:26=E2=80=AFAM Patrick Palka = wrote: > > Here we're crashing during satisfaction for the NTTP 'C auto' from > do_auto_deduction ultimately because convert_template_argument / unify > don't pass all outer template arguments to do_auto_deduction, and during > satisfaction we need to know all arguments. While these callers do > pass some outer arguments, they are only sufficient to properly > substitute the 'auto' and are not necessarily the complete set. > > Fortunately it seems it's possible to obtain the full set of outer > arguments from these callers via convert_template_argument's IN_DECL > parameter and unify's TPARMS parameter. So this patch adds a TMPL > parameter to do_auto_deduction, used only during adc_unify deduction, > which contains the (partially instantiated) template corresponding to > this auto and from which we can obtain all outer template arguments for > satisfaction. > > This patch also adjusts the IN_DECL argument passed to > coerce_template_parms from tsubst_decl so that we could in turn safely > assume convert_template_argument's IN_DECL is always a TEMPLATE_DECL, > and thus could pass it as-is to do_auto_deduction. (tsubst_decl seems > to be the only caller that passes a non-empty non-template IN_DECL to > coerce_template_parms.) > > Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for > trunk/12? Ping. > > PR c++/109160 > > gcc/cp/ChangeLog: > > * cp-tree.h (do_auto_deduction): Add defaulted TMPL parameter. > * pt.cc (convert_template_argument): Pass IN_DECL as TMPL to > do_auto_deduction. > (tsubst_decl) : Pass TMPL instead of T as > IN_DECL to coerce_template_parms. > (unify) : Pass the corresponding > template as TMPL to do_auto_deduction. > (do_auto_deduction): Document default arguments. Use TMPL > to obtain a full set of template arguments for satisfaction > in the adc_unify case. > > gcc/testsuite/ChangeLog: > > * g++.dg/cpp2a/concepts-placeholder12.C: New test. > --- > gcc/cp/cp-tree.h | 3 +- > gcc/cp/pt.cc | 30 ++++++++++++++----- > .../g++.dg/cpp2a/concepts-placeholder12.C | 29 ++++++++++++++++++ > 3 files changed, 53 insertions(+), 9 deletions(-) > create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-placeholder12.C > > diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h > index dfc1c845768..e7190c5cc62 100644 > --- a/gcc/cp/cp-tree.h > +++ b/gcc/cp/cp-tree.h > @@ -7324,7 +7324,8 @@ extern tree do_auto_deduction (tr= ee, tree, tree, > auto_deduction_context > =3D adc_unspecified, > tree =3D NULL_TREE, > - int =3D LOOKUP_NORMAL); > + int =3D LOOKUP_NORMAL, > + tree =3D NULL_TREE); > extern tree type_uses_auto (tree); > extern tree type_uses_auto_or_concept (tree); > extern void append_type_to_template_for_access_check (tree, tree, tree, > diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc > index ddbd73371b9..6400b686a58 100644 > --- a/gcc/cp/pt.cc > +++ b/gcc/cp/pt.cc > @@ -8638,7 +8638,7 @@ convert_template_argument (tree parm, > else if (tree a =3D type_uses_auto (t)) > { > t =3D do_auto_deduction (t, arg, a, complain, adc_unify, args, > - LOOKUP_IMPLICIT); > + LOOKUP_IMPLICIT, in_decl); > if (t =3D=3D error_mark_node) > return error_mark_node; > } > @@ -15243,7 +15243,7 @@ tsubst_decl (tree t, tree args, tsubst_flags_t co= mplain) > the template. */ > argvec =3D (coerce_template_parms > (DECL_TEMPLATE_PARMS (gen_tmpl), > - argvec, t, complain)); > + argvec, tmpl, complain)); > if (argvec =3D=3D error_mark_node) > RETURN (error_mark_node); > hash =3D spec_hasher::hash (gen_tmpl, argvec); > @@ -24655,7 +24655,9 @@ unify (tree tparms, tree targs, tree parm, tree a= rg, int strict, > if (tree a =3D type_uses_auto (tparm)) > { > tparm =3D do_auto_deduction (tparm, arg, a, > - complain, adc_unify, targs); > + complain, adc_unify, targs, > + LOOKUP_NORMAL, > + TPARMS_PRIMARY_TEMPLATE (tparms)= ); > if (tparm =3D=3D error_mark_node) > return 1; > } > @@ -30643,13 +30645,20 @@ unparenthesized_id_or_class_member_access_p (tr= ee init) > adc_requirement contexts to communicate the necessary template argume= nts > to satisfaction. OUTER_TARGS is ignored in other contexts. > > - For partial-concept-ids, extra args may be appended to the list of de= duced > - template arguments prior to determining constraint satisfaction. */ > + Additionally for adc_unify contexts TMPL is the template for which th= is > + auto is a template parameter type. > + > + For partial-concept-ids, extra args from OUTER_TARGS, TMPL and the cu= rrent > + scope may be appended to the list of deduced template arguments prior= to > + determining constraint satisfaction as appropriate. */ > > tree > do_auto_deduction (tree type, tree init, tree auto_node, > - tsubst_flags_t complain, auto_deduction_context conte= xt, > - tree outer_targs, int flags) > + tsubst_flags_t complain /* =3D tf_warning_or_error */, > + auto_deduction_context context /* =3D adc_unspecified = */, > + tree outer_targs /* =3D NULL_TREE */, > + int flags /* =3D LOOKUP_NORMAL */, > + tree tmpl /* =3D NULL_TREE */) > { > if (init =3D=3D error_mark_node) > return error_mark_node; > @@ -30839,7 +30848,12 @@ do_auto_deduction (tree type, tree init, tree au= to_node, > } > } > > - tree full_targs =3D add_to_template_args (outer_targs, targs); > + tree full_targs =3D outer_targs; > + > + if (context =3D=3D adc_unify) > + full_targs =3D add_outermost_template_args (tmpl, full_targs); > + > + full_targs =3D add_to_template_args (full_targs, targs); > > /* HACK: Compensate for callers not always communicating all level= s of > outer template arguments by filling in the outermost missing lev= els > diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-placeholder12.C b/gcc/te= stsuite/g++.dg/cpp2a/concepts-placeholder12.C > new file mode 100644 > index 00000000000..3d4d138720e > --- /dev/null > +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-placeholder12.C > @@ -0,0 +1,29 @@ > +// PR c++/109160 > +// { dg-do compile { target c++20 } } > + > +template > +concept C =3D B; > + > +template struct X { }; > + > +template > +struct A { > + template auto V> static void f(); > + template auto V> static void g(X); > + template auto V> static inline int value =3D V; > + template auto V> struct D { }; > +}; > + > +int main() { > + A::f<0>(); > + A::f<0>(); // { dg-error "no match|constraints" } > + > + A::g(X<0>{}); > + A::g(X<0>{}); // { dg-error "no match|constraints" } > + > + bool v1 =3D A::value<0>; > + bool v2 =3D A::value<0>; // { dg-error "constraints" } > + > + A::D<0> d1; > + A::D<0> d2; // { dg-error "constraints" } > +} > -- > 2.40.0 >