From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 3605A3939C24 for ; Mon, 19 Apr 2021 21:31:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 3605A3939C24 Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-92-SpsvAgPzPd-9DB_M1UJrAQ-1; Mon, 19 Apr 2021 17:31:04 -0400 X-MC-Unique: SpsvAgPzPd-9DB_M1UJrAQ-1 Received: by mail-qt1-f199.google.com with SMTP id o21-20020a05622a0095b02901b1324f9fceso9838595qtw.8 for ; Mon, 19 Apr 2021 14:31:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=nNG9ummjeWbUWOWTUbh5TtpodoqzZjc8hicB8ZaquQo=; b=cRX1lsLhpUbN7wmlKyugASlEeCPAvGZFPNmfv6FcqHwVwSdvrDK6mCUWrGjc6zMZ56 zRWblUtnvmFa9AmXbi3+JBiLWCOUhbt9FAm35F9Z/Hz56GhtzBDmcveZqwWEn/U2mVx3 CR0jUT9uT55NdCBD5pqPbFKjK3hN2NddTwhmVH0vPlJ3ESc7IoWT0X2/3b3SXmTO6QGD yqjNXZ2KNSYrLOy6+9BASu7YQpt0nZoahtd+M64xhtJpt/afOTgl2RMK3RR1fwPFpdrS 1yo4oR8gOGFwVFkUGCvV3cStRAJHQBhjGyrcWisJSdMqYpngBPt2Y3lVOTYwat8zxkjX uqow== X-Gm-Message-State: AOAM530Q5QyDfJAC4WFRUKHPfNrAwiZL1DHN/c1IxnDHVOy7h85FsJ/4 UV/LDN2FW5Zqss3TCSNDkr/gaFaT+xGbQWF9T5/Sq0ReF2Z1L7Sq2IC4LfF4fMOj3yZ6hbNeKZ8 kTi9ax9lovbqG54rVsEY73X+WirJcTntGxzYfRG0E4kVcb6f3SYxIFLMQxhaT85NEmw== X-Received: by 2002:a37:42cb:: with SMTP id p194mr13241705qka.213.1618867863449; Mon, 19 Apr 2021 14:31:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyPAZXUoXAYdlOwjDdE0/dQOEJqmbmbTFhD/++XKT5oDKLLXhHFnmkXz5cqK9TU1FjCIIHNMw== X-Received: by 2002:a37:42cb:: with SMTP id p194mr13241678qka.213.1618867863043; Mon, 19 Apr 2021 14:31:03 -0700 (PDT) Received: from [192.168.1.148] (209-6-216-142.s141.c3-0.smr-cbr1.sbo-smr.ma.cable.rcncustomer.com. [209.6.216.142]) by smtp.gmail.com with ESMTPSA id w15sm9854110qtn.12.2021.04.19.14.31.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 19 Apr 2021 14:31:02 -0700 (PDT) Subject: Re: [PATCH] c++: Fix pretty printing of function pointer type [PR98767] To: Patrick Palka , gcc-patches@gcc.gnu.org References: <20210416225830.3897124-1-ppalka@redhat.com> From: Jason Merrill Message-ID: <5d6a0776-5d4c-dfa0-d6bd-8621ce357837@redhat.com> Date: Mon, 19 Apr 2021 17:31:01 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.9.0 MIME-Version: 1.0 In-Reply-To: <20210416225830.3897124-1-ppalka@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-15.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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, 19 Apr 2021 21:31:07 -0000 On 4/16/21 6:58 PM, Patrick Palka wrote: > When pretty printing a function pointer type via > pp_cxx_parameter_declaration_clause, we end up always printing an empty > parameter list because the loop that's supposed to print the parameter > list iterates over 'args' instead of 'types', and 'args' is empty in > this case when a FUNCTION_TYPE is passed to this routine (as opposed > to a FUNCTION_DECL). > > This patch fixes this by making the loop iterator over 'types' instead. > This patch also moves the retrofitted PARM_DECL printing from this > routine to pp_cxx_requires_expr, the only caller that uses it. This > simplification lets us easily output the trailing '...' in the parameter > list of a variadic function, which this patch also implements. > > Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for > trunk? OK. > gcc/cp/ChangeLog: > > PR c++/98767 > * cxx-pretty-print.c (pp_cxx_parameter_declaration_clause): Fix > loop over parameter list to iterate over 'types' instead of > 'args'. Output the trailing '...' for a variadic function. > Remove PARM_DECL support. > (pp_cxx_requires_expr): Pretty print the parameter list directly > instead of going through pp_cxx_parameter_declaration_clause. > > gcc/testsuite/ChangeLog: > > PR c++/98767 > * g++.dg/concepts/diagnostic16.C: New test. > --- > gcc/cp/cxx-pretty-print.c | 48 ++++++++++++-------- > gcc/testsuite/g++.dg/concepts/diagnostic16.C | 17 +++++++ > 2 files changed, 46 insertions(+), 19 deletions(-) > create mode 100644 gcc/testsuite/g++.dg/concepts/diagnostic16.C > > diff --git a/gcc/cp/cxx-pretty-print.c b/gcc/cp/cxx-pretty-print.c > index a22eea5239c..894472e26e0 100644 > --- a/gcc/cp/cxx-pretty-print.c > +++ b/gcc/cp/cxx-pretty-print.c > @@ -1537,34 +1537,27 @@ pp_cxx_parameter_declaration (cxx_pretty_printer *pp, tree t) > static void > pp_cxx_parameter_declaration_clause (cxx_pretty_printer *pp, tree t) > { > - tree args; > - tree types; > - bool abstract; > - > - // For a requires clause or the explicit printing of a parameter list > - // we expect T to be a chain of PARM_DECLs. Otherwise, the list of > - // args and types are taken from the function decl T. > - if (TREE_CODE (t) == PARM_DECL) > + gcc_assert (FUNC_OR_METHOD_TYPE_P (t) || TREE_CODE (t) == FUNCTION_DECL); > + tree types, args; > + if (TYPE_P (t)) > { > - args = t; > - types = t; > - abstract = false; > + types = TYPE_ARG_TYPES (t); > + args = NULL_TREE; > } > else > { > - bool type_p = TYPE_P (t); > - args = type_p ? NULL : FUNCTION_FIRST_USER_PARM (t); > - types = type_p ? TYPE_ARG_TYPES (t) : FUNCTION_FIRST_USER_PARMTYPE (t); > - abstract = args == NULL || pp->flags & pp_c_flag_abstract; > + types = FUNCTION_FIRST_USER_PARMTYPE (t); > + args = FUNCTION_FIRST_USER_PARM (t); > } > - bool first = true; > + bool abstract = !args || (pp->flags & pp_c_flag_abstract); > > /* Skip artificial parameter for non-static member functions. */ > if (TREE_CODE (t) == METHOD_TYPE) > types = TREE_CHAIN (types); > > + bool first = true; > pp_cxx_left_paren (pp); > - for (; args; args = TREE_CHAIN (args), types = TREE_CHAIN (types)) > + for (; types && types != void_list_node; types = TREE_CHAIN (types)) > { > if (!first) > pp_cxx_separate_with (pp, ','); > @@ -1577,6 +1570,14 @@ pp_cxx_parameter_declaration_clause (cxx_pretty_printer *pp, tree t) > pp_cxx_whitespace (pp); > pp->assignment_expression (TREE_PURPOSE (types)); > } > + if (!abstract) > + args = TREE_CHAIN (args); > + } > + if (!types) > + { > + if (!first) > + pp_cxx_separate_with (pp, ','); > + pp_cxx_ws_string (pp, "..."); > } > pp_cxx_right_paren (pp); > } > @@ -2775,9 +2776,18 @@ void > pp_cxx_requires_expr (cxx_pretty_printer *pp, tree t) > { > pp_string (pp, "requires"); > - if (tree parms = TREE_OPERAND (t, 0)) > + if (tree parms = REQUIRES_EXPR_PARMS (t)) > { > - pp_cxx_parameter_declaration_clause (pp, parms); > + bool first = true; > + pp_cxx_left_paren (pp); > + for (; parms; parms = TREE_CHAIN (parms)) > + { > + if (!first) > + pp_cxx_separate_with (pp, ',' ); > + first = false; > + pp_cxx_parameter_declaration (pp, parms); > + } > + pp_cxx_right_paren (pp); > pp_cxx_whitespace (pp); > } > pp_cxx_requirement_body (pp, TREE_OPERAND (t, 1)); > diff --git a/gcc/testsuite/g++.dg/concepts/diagnostic16.C b/gcc/testsuite/g++.dg/concepts/diagnostic16.C > new file mode 100644 > index 00000000000..49d5733faea > --- /dev/null > +++ b/gcc/testsuite/g++.dg/concepts/diagnostic16.C > @@ -0,0 +1,17 @@ > +// PR c++/98767 > +// { dg-do compile { target c++20 } } > + > +template > +concept Callable = requires(Function func, Args... args) { func(args...); }; > + > +static_assert(Callable); // { dg-error "failed" } > +// { dg-message {Function = int \(\*\)\(\)} "" { target *-*-* } 5 } > + > +static_assert(Callable); // { dg-error "failed" } > +// { dg-message {Function = char \(\*\)\(int\*\)} "" { target *-*-* } 5 } > + > +static_assert(Callable); // { dg-error "failed" } > +// { dg-message {Function = short int \(\*\)\(int\*, int\)} "" { target *-*-* } 5 } > + > +static_assert(Callable); // { dg-error "failed" } > +// { dg-message {Function = long int \(\*\)\(int\*, int, \.\.\.\)} "" { target *-*-* } 5 } >