From patchwork Fri Nov 26 15:24:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Matthias Kretz X-Patchwork-Id: 48197 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6547B3857C53 for ; Fri, 26 Nov 2021 15:25:54 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from lxmtout2.gsi.de (lxmtout2.gsi.de [140.181.3.112]) by sourceware.org (Postfix) with ESMTPS id 08328385780E for ; Fri, 26 Nov 2021 15:24:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 08328385780E 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 lxmtout2.gsi.de (Postfix) with ESMTP id 24392202AD67; Fri, 26 Nov 2021 16:24:56 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at lxmtout2.gsi.de Received: from lxmtout2.gsi.de ([127.0.0.1]) by localhost (lxmtout2.gsi.de [127.0.0.1]) (amavisd-new, port 10024) with LMTP id IGEQl3LMnBnZ; Fri, 26 Nov 2021 16:24:56 +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 lxmtout2.gsi.de (Postfix) with ESMTPS id 07DE6202AD65; Fri, 26 Nov 2021 16:24:56 +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.2375.17; Fri, 26 Nov 2021 16:24:55 +0100 From: Matthias Kretz To: , Subject: [PATCH 2/2] c++: Print function template parms when relevant [part 2] Date: Fri, 26 Nov 2021 16:24:55 +0100 Message-ID: <9989745.nUPlyArG6x@excalibur> Organization: GSI Helmholtzzentrum =?utf-8?q?f=C3=BCr?= Schwerionenforschung In-Reply-To: <1800263.tdWV9SEqCh@excalibur> References: <1800263.tdWV9SEqCh@excalibur> MIME-Version: 1.0 X-Originating-IP: [140.181.3.12] X-ClientProxiedBy: srvex4.Campus.gsi.de (10.10.4.36) To srvex3.campus.gsi.de (10.10.4.16) X-Spam-Status: No, score=-10.2 required=5.0 tests=BAYES_00, BODY_8BITS, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H2, SPF_PASS, TXREP, T_SPF_HELO_PERMERROR 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: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Restore status-quo how function template specializations were diagnosed. Signed-off-by: Matthias Kretz gcc/testsuite/ChangeLog: * g++.dg/diagnostic/default-template-args-1.C: Adjust for different presentation of function template specializations. * g++.dg/ext/pretty1.C: Ditto. * g++.old-deja/g++.ext/pretty3.C: Ditto. * g++.old-deja/g++.pt/memtemp77.C: Ditto. gcc/cp/ChangeLog: * error.c (dump_function_decl): Pretty print all template specializations. (dump_function_name): Only print template parms if given a function template specialization. --- gcc/cp/error.c | 18 ++++++++++-------- .../diagnostic/default-template-args-1.C | 4 ++-- gcc/testsuite/g++.dg/ext/pretty1.C | 2 +- gcc/testsuite/g++.old-deja/g++.ext/pretty3.C | 2 +- gcc/testsuite/g++.old-deja/g++.pt/memtemp77.C | 2 +- 5 files changed, 15 insertions(+), 13 deletions(-) -- ────────────────────────────────────────────────────────────────────────── Dr. Matthias Kretz https://mattkretz.github.io GSI Helmholtz Centre for Heavy Ion Research https://gsi.de stdₓ::simd ────────────────────────────────────────────────────────────────────────── diff --git a/gcc/cp/error.c b/gcc/cp/error.c index fb62adbeb0b..9365e42dd76 100644 --- a/gcc/cp/error.c +++ b/gcc/cp/error.c @@ -1723,9 +1723,8 @@ dump_function_decl (cxx_pretty_printer *pp, tree t, int flags) tree specialized_t = t; int specialized_flags = 0; - /* Pretty print only template instantiations. Don't pretty print explicit - specializations like 'template <> void fun (int)'. */ - if (DECL_TEMPLATE_INSTANTIATION (t) && DECL_TEMPLATE_INFO (t) + /* Pretty print template instantiations only. */ + if (DECL_USE_TEMPLATE (t) && DECL_TEMPLATE_INFO (t) && !(flags & TFF_NO_TEMPLATE_BINDINGS) && flag_pretty_templates) { @@ -1989,9 +1988,11 @@ dump_function_name (cxx_pretty_printer *pp, tree t, int flags) dump_module_suffix (pp, t); /* Print function template parameters if: - 1. t is template, and - 2. the caller didn't request to only print the template-name, and - 3. t actually has template parameters that are not indirect parameters from + 1. t is a template, and + 2. t is a specialization of a template (so that __FUNCTION__ of + 'template void f(T)' is 'f' and not 'f'), and + 3. the caller didn't request to only print the template-name, and + 4. t actually has template parameters that are not indirect parameters from enclosing scopes, i.e. either - t is a friend template specialization (eg. template struct X { friend void foo(int); }; since @@ -1999,7 +2000,7 @@ dump_function_name (cxx_pretty_printer *pp, tree t, int flags) before PRIMARY_TEMPLATE_P is safe to call), or - t is a primary template (own template header), and - 4. either + 5. either - flags requests to show no function arguments, in which case deduced types could be hidden and thus need to be printed, or - at least one function template argument was given explicitly and the @@ -2009,6 +2010,7 @@ dump_function_name (cxx_pretty_printer *pp, tree t, int flags) dump_template_parms. */ if (DECL_TEMPLATE_INFO (t) + && DECL_USE_TEMPLATE (t) && !(flags & TFF_TEMPLATE_NAME) && (TREE_CODE (DECL_TI_TEMPLATE (t)) != TEMPLATE_DECL || PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (t))) @@ -2016,7 +2018,7 @@ dump_function_name (cxx_pretty_printer *pp, tree t, int flags) || (DECL_TI_ARGS (t) && EXPLICIT_TEMPLATE_ARGS_P (INNERMOST_TEMPLATE_ARGS (DECL_TI_ARGS (t)))))) - dump_template_parms (pp, DECL_TEMPLATE_INFO (t), !DECL_USE_TEMPLATE (t), flags); + dump_template_parms (pp, DECL_TEMPLATE_INFO (t), false, flags); } /* Dump the template parameters from the template info INFO under control of diff --git a/gcc/testsuite/g++.dg/diagnostic/default-template-args-1.C b/gcc/testsuite/g++.dg/diagnostic/default-template-args-1.C index 6481798a69b..1b82ea46bb5 100644 --- a/gcc/testsuite/g++.dg/diagnostic/default-template-args-1.C +++ b/gcc/testsuite/g++.dg/diagnostic/default-template-args-1.C @@ -43,8 +43,8 @@ int main() f3(1); // { dg-warning "'void f3\\(a\\) .with a = float.'" } f3(1); // { dg-warning "'void f3\\(a\\) .with a = float; int b = 2.'" } f4(1.); // { dg-warning "'void f4\\(a\\) .with a = double.'" } - f4(1); // { dg-warning "'void f4\\(int\\)'" } - f4(1.f); // { dg-warning "'void f4\\(float\\)'" } + f4(1); // { dg-warning "'void f4\\(a\\) .with a = int.'" } + f4(1.f); // { dg-warning "'void f4\\(a\\) .with a = float.'" } f0(0); // { dg-error "" } f1(0); // { dg-error "" } diff --git a/gcc/testsuite/g++.dg/ext/pretty1.C b/gcc/testsuite/g++.dg/ext/pretty1.C index c5bfd6082a7..07cc9a6f2cd 100644 --- a/gcc/testsuite/g++.dg/ext/pretty1.C +++ b/gcc/testsuite/g++.dg/ext/pretty1.C @@ -60,7 +60,7 @@ __assert_fail (const char *cond, const char *file, unsigned int line, abort (); } -// { dg-final { scan-assembler "int bar\\(int\\)" } } +// { dg-final { scan-assembler "int bar\\(T\\).*with T = int" } } // { dg-final { scan-assembler "top level" } } // { dg-final { scan-assembler "int main\\(\\)" } } // { dg-final { scan-assembler "int bar\\(T\\).*with T = double" } } diff --git a/gcc/testsuite/g++.old-deja/g++.ext/pretty3.C b/gcc/testsuite/g++.old-deja/g++.ext/pretty3.C index 30c7ecd5065..6c82f5b6061 100644 --- a/gcc/testsuite/g++.old-deja/g++.ext/pretty3.C +++ b/gcc/testsuite/g++.old-deja/g++.ext/pretty3.C @@ -35,7 +35,7 @@ template<> void f1 (int) if (strcmp (function, "f1")) bad = true; - if (strcmp (pretty, "void f1(int)")) + if (strcmp (pretty, "void f1(T) [with T = int]")) bad = true; } diff --git a/gcc/testsuite/g++.old-deja/g++.pt/memtemp77.C b/gcc/testsuite/g++.old-deja/g++.pt/memtemp77.C index 93dbf4b489f..6dd4b546c0c 100644 --- a/gcc/testsuite/g++.old-deja/g++.pt/memtemp77.C +++ b/gcc/testsuite/g++.old-deja/g++.pt/memtemp77.C @@ -19,7 +19,7 @@ const char* S3::h(int) { return __PRETTY_FUNCTION__; } int main() { if (strcmp (S3::h(7), - "static const char* S3::h(int)") == 0) + "static const char* S3::h(U) [with U = int; T = double]") == 0) return 0; else return 1;