From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1888) id AA09E3858D1E; Wed, 20 Sep 2023 16:11:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AA09E3858D1E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1695226308; bh=m9QMF4aMURzZ2T+Ksv1XTySUPSo6LK7AnMygBoLy2yM=; h=From:To:Subject:Date:From; b=WC6KptUjzWgCw6WIGuZmnmVUtzCVJo4AKFYldK2xmgodMNTS0mpZ/y7VcJ5hAELUq 1O6GmoKkHvOPOGdCSK4bi0zjombMMtfasGjmoNyk+YN59EV8i1jzYKZClmcvn2837m Zng9oZpPmjItmsom27o2ypBi0ge53oB+yp/Bilj8= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Patrick Palka To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-4178] c++: improve class NTTP object pretty printing [PR111471] X-Act-Checkin: gcc X-Git-Author: Patrick Palka X-Git-Refname: refs/heads/master X-Git-Oldrev: 915574e538322aad5195bc3b6be2a4f85bbd2467 X-Git-Newrev: 75c4b0cde4835b45350da0a5cd82f1d1a0a7a2f1 Message-Id: <20230920161148.AA09E3858D1E@sourceware.org> Date: Wed, 20 Sep 2023 16:11:48 +0000 (GMT) List-Id: https://gcc.gnu.org/g:75c4b0cde4835b45350da0a5cd82f1d1a0a7a2f1 commit r14-4178-g75c4b0cde4835b45350da0a5cd82f1d1a0a7a2f1 Author: Patrick Palka Date: Wed Sep 20 12:09:36 2023 -0400 c++: improve class NTTP object pretty printing [PR111471] 1. Move class NTTP object pretty printing to a more general spot in the pretty printer, so that we always print its value instead of its (mangled) name even when it appears outside of a template argument list. 2. Print the type of an class NTTP object alongside its CONSTRUCTOR value, like dump_expr would have done. 3. Don't print const VIEW_CONVERT_EXPR wrappers for class NTTPs. PR c++/111471 gcc/cp/ChangeLog: * cxx-pretty-print.cc (cxx_pretty_printer::expression) : Handle class NTTP objects by printing their type and value. : Strip const VIEW_CONVERT_EXPR wrappers for class NTTPs. (pp_cxx_template_argument_list): Don't handle class NTTP objects here. gcc/testsuite/ChangeLog: * g++.dg/concepts/diagnostic19.C: New test. Diff: --- gcc/cp/cxx-pretty-print.cc | 19 +++++++++++++++++-- gcc/testsuite/g++.dg/concepts/diagnostic19.C | 20 ++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/gcc/cp/cxx-pretty-print.cc b/gcc/cp/cxx-pretty-print.cc index 909a9dc917f..eb16e63425f 100644 --- a/gcc/cp/cxx-pretty-print.cc +++ b/gcc/cp/cxx-pretty-print.cc @@ -1121,6 +1121,15 @@ cxx_pretty_printer::expression (tree t) t = OVL_FIRST (t); /* FALLTHRU */ case VAR_DECL: + if (DECL_NTTP_OBJECT_P (t)) + { + /* Print the type followed by the CONSTRUCTOR value of the + NTTP object. */ + simple_type_specifier (cv_unqualified (TREE_TYPE (t))); + expression (DECL_INITIAL (t)); + break; + } + /* FALLTHRU */ case PARM_DECL: case FIELD_DECL: case CONST_DECL: @@ -1261,6 +1270,14 @@ cxx_pretty_printer::expression (tree t) pp_cxx_right_paren (this); break; + case VIEW_CONVERT_EXPR: + if (TREE_CODE (TREE_OPERAND (t, 0)) == TEMPLATE_PARM_INDEX) + { + /* Strip const VIEW_CONVERT_EXPR wrappers for class NTTPs. */ + expression (TREE_OPERAND (t, 0)); + break; + } + /* FALLTHRU */ default: c_pretty_printer::expression (t); break; @@ -1966,8 +1983,6 @@ pp_cxx_template_argument_list (cxx_pretty_printer *pp, tree t) if (TYPE_P (arg) || (TREE_CODE (arg) == TEMPLATE_DECL && TYPE_P (DECL_TEMPLATE_RESULT (arg)))) pp->type_id (arg); - else if (VAR_P (arg) && DECL_NTTP_OBJECT_P (arg)) - pp->expression (DECL_INITIAL (arg)); else pp->expression (arg); } diff --git a/gcc/testsuite/g++.dg/concepts/diagnostic19.C b/gcc/testsuite/g++.dg/concepts/diagnostic19.C new file mode 100644 index 00000000000..70af30b8d4f --- /dev/null +++ b/gcc/testsuite/g++.dg/concepts/diagnostic19.C @@ -0,0 +1,20 @@ +// Verify pretty printing of class NTTP objects. +// PR c++/111471 +// { dg-do compile { target c++20 } } + +struct A { bool value; }; + +template + requires (V.value) // { dg-message {'\(V\).value \[with V = A\{false\}\]'} } +void f(); + +template struct B { static constexpr auto value = V.value; }; + +template + requires T::value // { dg-message {'T::value \[with T = B\]'} } +void g(); + +int main() { + f(); // { dg-error "no match" } + g>(); // { dg-error "no match" } +}