From patchwork Tue Sep 19 16:40:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1836786 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=M3DsfpEv; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RqnVL1LdMz1ynZ for ; Wed, 20 Sep 2023 02:41:13 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 587413856DC6 for ; Tue, 19 Sep 2023 16:41:11 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 432093858D20 for ; Tue, 19 Sep 2023 16:40:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 432093858D20 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=1695141658; 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; bh=5RGe6Tl8Asz0Blnn8qnEfCS5MC7Gdy1wnG0TbOKaYVI=; b=M3DsfpEvRJ5lvbYCOmv9kX6CKvGUew2wfn3Q6D4qpPFnZmNo6ODdrh6FjC7Q0dX0UqhaJJ HRaLC2mwdolC1LcXCFg+6IWqIwipnADFLl54BWoxf6Pznzm40YfV1raGOONwSaNtuvQxIW KUsaX4zDTT+gqfI649c0Z3V6MPTHN6g= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-655-dowBQOyOMRWUT5zsZx-GUw-1; Tue, 19 Sep 2023 12:40:57 -0400 X-MC-Unique: dowBQOyOMRWUT5zsZx-GUw-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-773eedbd759so15320185a.2 for ; Tue, 19 Sep 2023 09:40:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695141657; x=1695746457; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=5RGe6Tl8Asz0Blnn8qnEfCS5MC7Gdy1wnG0TbOKaYVI=; b=cTsrlBcGegU45hnf1i8dBAhKY43NRUJQhdJAOZKZiCw4KYa9C3WjyQqSc1FqWnZ+/S Tec6HP3ttYbCiTa7sTlsmWHCxUlMKfKVCLh9DD07I/Dmyriijps21Ztl+buLLhRzIdQb KbFuX1r2WbJ2tdN51yTM79GzlKdNqDk/oHcfbIPNTlD5lrRv4/FMQB0wKMfpsAY7xdwm IA8iW97f6imBqDYhaPiLhyLtSvajXMmxvwfOfRFpSZiehGSyz3uDuqND2MnHwiKzny8Y ZZ/LO2minEP9yySt+bDJfw69EjMbJU9qZyCz/J5Xw7JXqR3i+HpsiByuvUTsR5JJkBwW xehQ== X-Gm-Message-State: AOJu0YwsXPYjqrs1UkghfKvkra9lby4jkymabTcC2988tX8ubHFgozzX N6JYCgL4frysmk1mgwEfHZcVtqryYXX8AyeJjm4T+7OaHW1VLboVscHjJAMDKOeoy1BuCj2gknu jN4g5LMYfm5/VoedPURV1ruwwrexKKOjHk8eenVwtjeWbIawQfhv6mPkXVPP/vWBbJUwY/KLMeV g= X-Received: by 2002:a05:620a:28cf:b0:773:c864:35aa with SMTP id l15-20020a05620a28cf00b00773c86435aamr234116qkp.26.1695141656946; Tue, 19 Sep 2023 09:40:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGmIizmFhytxxqSTs9gXXkUsREDxMGYKg3nxk7yRSKq53eWipVuNhJTz0u2F47GR6eszTZbwQ== X-Received: by 2002:a05:620a:28cf:b0:773:c864:35aa with SMTP id l15-20020a05620a28cf00b00773c86435aamr234101qkp.26.1695141656683; Tue, 19 Sep 2023 09:40:56 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id c19-20020a05620a135300b0076f16e98851sm4077327qkl.102.2023.09.19.09.40.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 09:40:56 -0700 (PDT) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] c++: improve class NTTP object pretty printing [PR111471] Date: Tue, 19 Sep 2023 12:40:54 -0400 Message-ID: <20230919164055.728094-1-ppalka@redhat.com> X-Mailer: git-send-email 2.42.0.216.gbda494f404 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.6 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_H4, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Tested on x86_64-pc-linux-gnu, does this look OK for trunk/13? -- >8 -- 1. Move class NTTP object pretty printing to a more general spot in the pretty printer. 2. Print the type of an class NTTP object alongside its CONSTRUCTOR value, like dump_expr would have done. 3. Don't pretty print const VIEW_CONVERT_EXPR wrapping class NTTPs. PR c++/111471 gcc/cp/ChangeLog: * cxx-pretty-print.cc (cxx_pretty_printer::expression) : Print the value of a class NTTP object. : Strip cosnt VIEW_CONVERT_EXPR wrappers for class NTTPs. (pp_cxx_template_argument_list): Don't handle the class NTTP objects here. gcc/testsuite/ChangeLog: * g++.dg/concepts/diagnostic19.C: New test. --- gcc/cp/cxx-pretty-print.cc | 19 +++++++++++++++++-- gcc/testsuite/g++.dg/concepts/diagnostic19.C | 20 ++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/concepts/diagnostic19.C diff --git a/gcc/cp/cxx-pretty-print.cc b/gcc/cp/cxx-pretty-print.cc index 909a9dc917f..7cd43151592 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 an + 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..20cdb63380b --- /dev/null +++ b/gcc/testsuite/g++.dg/concepts/diagnostic19.C @@ -0,0 +1,20 @@ +// Verify our 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" } +}