From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lxmtout1.gsi.de (lxmtout1.gsi.de [140.181.3.111]) by sourceware.org (Postfix) with ESMTPS id A9D2D3858D3C for ; Mon, 8 Nov 2021 20:00:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A9D2D3858D3C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gsi.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gsi.de Received: from localhost (localhost [127.0.0.1]) by lxmtout1.gsi.de (Postfix) with ESMTP id 71AA92050D05; Mon, 8 Nov 2021 21:00:23 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at lxmtout1.gsi.de Received: from lxmtout1.gsi.de ([127.0.0.1]) by localhost (lxmtout1.gsi.de [127.0.0.1]) (amavisd-new, port 10024) with LMTP id Cnvlu8Ummfby; Mon, 8 Nov 2021 21:00:23 +0100 (CET) Received: from srvex3.campus.gsi.de (unknown [10.10.4.16]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by lxmtout1.gsi.de (Postfix) with ESMTPS id 5917F2050D00; Mon, 8 Nov 2021 21:00:23 +0100 (CET) Received: from excalibur.localnet (140.181.3.12) by srvex3.campus.gsi.de (10.10.4.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2242.12; Mon, 8 Nov 2021 21:00:22 +0100 From: Matthias Kretz To: , Jason Merrill Subject: Re: [RFC] c++: Print function template parms when relevant (was: [PATCH v4] c++: Add gnu::diagnose_as attribute) Date: Mon, 8 Nov 2021 21:00:22 +0100 Message-ID: <1752408.vAW0rqQIy0@excalibur> Organization: GSI Helmholtzzentrum =?UTF-8?B?ZsO8cg==?= Schwerionenforschung In-Reply-To: <1694479.jsd7nNDzyu@excalibur> References: <4361366.VLH7GnMWUR@minbar> <1694479.jsd7nNDzyu@excalibur> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="UTF-8" X-Originating-IP: [140.181.3.12] X-ClientProxiedBy: srvex3.Campus.gsi.de (10.10.4.16) To srvex3.campus.gsi.de (10.10.4.16) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00, BODY_8BITS, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP 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-List-Received-Date: Mon, 08 Nov 2021 20:00:26 -0000 I forgot to mention why I tagged it [RFC]: I needed one more bit of=20 information on the template args TREE_VEC to encode EXPLICIT_TEMPLATE_ARGS_= P.=20 Its TREE_CHAIN already points to an integer constant denoting the number of= =20 non-default arguments, so I couldn't trivially replace that. Therefore, I u= sed=20 the sign of that integer. I was hoping to find a cleaner solution, though. =2DMatthias On Monday, 8 November 2021 17:40:44 CET Matthias Kretz wrote: > On Tuesday, 17 August 2021 20:31:54 CET Jason Merrill wrote: > > > 2. Given a DECL_TI_ARGS tree, can I query whether an argument was > > > deduced > > > or explicitly specified? I'm asking because I still consider diagnost= ics > > > of function templates unfortunate. `template void f()` is > > > fine, > > > as is `void f(T) [with T =3D float]`, but `void f() [with T =3D float= ]` > > > could > > > be better. I.e. if the template parameter appears somewhere in the > > > function parameter list, dump_template_parms would only produce noise. > > > If, however, the template parameter was given explicitly, it would be > > > nice if it could show up accordingly in diagnostics. > >=20 > > NON_DEFAULT_TEMPLATE_ARGS_COUNT has that information, though there are > > some issues with it. Attached is my WIP from May to improve it > > somewhat, if that's interesting. >=20 > It is interesting. I used your patch to come up with the attached. Patch.= I > must say, I didn't try to read through all the cp/pt.c code to understand > all of what you did there (which is why my ChangeLog entry says "Jason?"), > but it works for me (and all of `make check`). >=20 > Anyway, I'd like to propose the following before finishing my diagnose_as > patch. I believe it's useful to fix this part first. The diagnostic/defau= lt- > template-args-[12].C tests show a lot of examples of the intent of this > patch. And the remaining changes to the testsuite show how it changes > diagnostic output. >=20 > ---------------------- 8< -------------------- >=20 > The choice when to print a function template parameter was still > suboptimal. That's because sometimes the function template parameter > list only adds noise, while in other situations the lack of a function > template parameter list makes diagnostic messages hard to understand. >=20 > The general idea of this change is to print template parms wherever they > would appear in the source code as well. Thus, the diagnostics code > needs to know whether any template parameter was given explicitly. >=20 > Signed-off-by: Matthias Kretz >=20 > gcc/testsuite/ChangeLog: >=20 > * g++.dg/debug/dwarf2/template-params-12n.C: Optionally, allow > DW_AT_default_value. > * g++.dg/diagnostic/default-template-args-1.C: New. > * g++.dg/diagnostic/default-template-args-2.C: New. > * g++.dg/diagnostic/param-type-mismatch-2.C: Expect template > parms in diagnostic. > * g++.dg/ext/pretty1.C: Expect function template specialization > to not pretty-print template parms. > * g++.old-deja/g++.ext/pretty3.C: Ditto. > * g++.old-deja/g++.pt/memtemp77.C: Ditto. > * g++.dg/goacc/template.C: Expect function template parms for > explicit arguments. > * g++.dg/gomp/declare-variant-7.C: Expect no function template > parms for deduced arguments. > * g++.dg/template/error40.C: Expect only non-default template > arguments in diagnostic. >=20 > gcc/cp/ChangeLog: >=20 > * cp-tree.h (GET_NON_DEFAULT_TEMPLATE_ARGS_COUNT): Return > absolute value of stored constant. > (EXPLICIT_TEMPLATE_ARGS_P): New. > (SET_EXPLICIT_TEMPLATE_ARGS_P): New. > (TFF_AS_PRIMARY): New constant. > * error.c (get_non_default_template_args_count): Avoid > GET_NON_DEFAULT_TEMPLATE_ARGS_COUNT if > NON_DEFAULT_TEMPLATE_ARGS_COUNT is a NULL_TREE. Make independent > of flag_pretty_templates. > (dump_template_bindings): Add flags parameter to be passed to > get_non_default_template_args_count. Print only non-default > template arguments. > (dump_function_decl): Call dump_function_name and dump_type of > the DECL_CONTEXT with specialized template and set > TFF_AS_PRIMARY for their flags. > (dump_function_name): Add and document conditions for calling > dump_template_parms. > (dump_template_parms): Print only non-default template > parameters. > * pt.c (determine_specialization): Jason? > (template_parms_level_to_args): Jason? > (copy_template_args): Jason? > (fn_type_unification): Set EXPLICIT_TEMPLATE_ARGS_P on the > template arguments tree if any template parameter was explicitly > given. > (type_unification_real): Jason? > (get_partial_spec_bindings): Jason? > (tsubst_template_args): Determine number of defaulted arguments > from new argument vector, if possible. > --- > gcc/cp/cp-tree.h | 18 +++- > gcc/cp/error.c | 83 ++++++++++++++----- > gcc/cp/pt.c | 58 +++++++++---- > .../g++.dg/debug/dwarf2/template-params-12n.C | 2 +- > .../diagnostic/default-template-args-1.C | 73 ++++++++++++++++ > .../diagnostic/default-template-args-2.C | 37 +++++++++ > .../g++.dg/diagnostic/param-type-mismatch-2.C | 2 +- > gcc/testsuite/g++.dg/ext/pretty1.C | 2 +- > gcc/testsuite/g++.dg/goacc/template.C | 8 +- > gcc/testsuite/g++.dg/gomp/declare-variant-7.C | 4 +- > gcc/testsuite/g++.dg/template/error40.C | 6 +- > gcc/testsuite/g++.old-deja/g++.ext/pretty3.C | 2 +- > gcc/testsuite/g++.old-deja/g++.pt/memtemp77.C | 2 +- > 13 files changed, 242 insertions(+), 55 deletions(-) > create mode 100644 > gcc/testsuite/g++.dg/diagnostic/default-template-args-1.C create mode > 100644 gcc/testsuite/g++.dg/diagnostic/default-template-args-2.C =2D-=20 =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80 Dr. Matthias Kretz https://mattkretz.github.io GSI Helmholtz Centre for Heavy Ion Research https://gsi.de std=E2=82=93::simd =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80