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: 141995 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp3526365vqi; Tue, 19 Sep 2023 09:41:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHSXcum5fBCwDP3MUzby52L38AiF22T+sYKiNCueHSkCOVEA0eA1cOTh3w66+UIy9IeCWhO X-Received: by 2002:a17:906:7693:b0:9a1:e231:67ec with SMTP id o19-20020a170906769300b009a1e23167ecmr10505302ejm.61.1695141693006; Tue, 19 Sep 2023 09:41:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695141692; cv=none; d=google.com; s=arc-20160816; b=NHcpS/5+APc1QuW7HQQQ60r6FUkRTYN3y6IZNFwLrYW+Bk9ySl5Kw6ePQTvhPfVGPe j/ppz8VCZK8/n+a4wZPEobPTdTheyt5R/N0EpLPz7xWondQ8mNnQae2dsb78IZMoKAxz 6j7tP1fJmV4zbld8/f2xroK709gQA05Isw7HoOGC73x5h3a5mD8YlyKJHjeN5krI6aVC tPtQ/lBD7l3T8Ead5rDOff+1HTBPP/4XkLcy5Qo0KDEYOsv3YAFridmWekn24zDvXx1U RaF6v5a5J2zOWF9cCzrnJpIVxyWppzRoKpr0dTrO12c+O0KDAWNqoCsMIGwiE6uysg6l HPRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :dmarc-filter:delivered-to; bh=5RGe6Tl8Asz0Blnn8qnEfCS5MC7Gdy1wnG0TbOKaYVI=; fh=1Hi9m88IqcWZGtfSxUrMGG+GBgL26N02X1SANXM6iTs=; b=meIIbAXEAw/pHv2BN/aTAatC5Kja4XPBxk+mLJncAT80JU1+oKUFKNA3woKok49lnM 1CCq5zZ5cVaeKMmkmvOlprw/aDrVSSpvKCdPhiAddDV+zZYvvtOGjTaVlrcqwRlvYARo nHsQKOQqKP8vsWOfiQXHntZx8A8dbai5/acBsfmwUrX/2B6FjFP3kq55APwMSUU+EndF XACkWodABZZyHkXHc/FWivJMIXVn7yQS+o+c+Y8TnMtpj/9W5K3HfVHizYGWcCzPtOnz YodJqqGZ21PymdbPvWsjOLCpyZ+ZfDZ9J+sl0UldKvLWgIg/Bv3JC5Lpu1wpBw//IO1e vWxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=M3DsfpEv; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id z15-20020a170906240f00b0099bbcfbd199si9421386eja.988.2023.09.19.09.41.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 09:41:32 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=M3DsfpEv; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 515DA385700D for ; Tue, 19 Sep 2023 16:41:23 +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-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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777484895917387727 X-GMAIL-MSGID: 1777484895917387727 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" } +}