From patchwork Thu Aug 29 20:57:12 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adam Butcher X-Patchwork-Id: 270944 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "www.sourceware.org", Issuer "StartCom Class 1 Primary Intermediate Server CA" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 2CFA42C00A3 for ; Fri, 30 Aug 2013 06:58:02 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id; q=dns; s=default; b=FoBmy7A36y5Z tWND0Pfdqa/cWWMWwc02AeEVZWpgwEThPegb2NovzFKQ+2Jaa4da5aCQ5pX+AMK9 zvzI4OQJvKdwXmVdJtWLnZvOleBks6+Jx5YR/h7jU+tWKxE2p4vk3yj6dLKSQv05 DYjDW2LqXFcsMLshlZfPe5n2MtJ8C/8= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id; s=default; bh=v7QfSi5XzCdVkpK/jI vSMNGh3E8=; b=Tc6pfNiT4D6eq2hukJqUE2YlO2AFzISPq1VjExNZWjuxrWo5ao 4S8/wbE5eD4iu9UQSMRlID5NeBhQv9BjZyPKa5msbSDDBQ3AdRDM/MyBBaddKWWm kOSN7kr3GJHWNfF0yoX3lW/X/EppV8wQlukWsGNU5Xho4Nw8mWvWgSnIU= Received: (qmail 20651 invoked by alias); 29 Aug 2013 20:57:55 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 20642 invoked by uid 89); 29 Aug 2013 20:57:55 -0000 Received: from mail-we0-f181.google.com (HELO mail-we0-f181.google.com) (74.125.82.181) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Thu, 29 Aug 2013 20:57:55 +0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.0 required=5.0 tests=ALL_TRUSTED, AWL, BAYES_00, FREEMAIL_FROM autolearn=ham version=3.3.2 X-HELO: mail-we0-f181.google.com Received: by mail-we0-f181.google.com with SMTP id q57so903414wes.40 for ; Thu, 29 Aug 2013 13:57:51 -0700 (PDT) X-Received: by 10.180.185.166 with SMTP id fd6mr16688416wic.5.1377809871523; Thu, 29 Aug 2013 13:57:51 -0700 (PDT) Received: from sphere.lan (munkyhouse.force9.co.uk. [84.92.244.81]) by mx.google.com with ESMTPSA id pn7sm342743wic.6.1969.12.31.16.00.00 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 29 Aug 2013 13:57:50 -0700 (PDT) From: Adam Butcher To: gcc-patches@gcc.gnu.org Cc: Jason Merrill , Gabriel Dos Reis , Andrew Sutton Subject: [PATCH, committed] Support dumping type bindings and 'mutable' qualifier in lambda diagnostics. Date: Thu, 29 Aug 2013 21:57:12 +0100 Message-Id: <1377809860-28282-1-git-send-email-adam@jessamine.co.uk> From: abutcher * error.c (dump_lambda_function): New function, dependent on ... (dump_substitution): ... this new function, factored out of ... (subst_to_string): ... here and ... (dump_function_decl): ... here. Updated to early-out with call to dump_lambda_function after determining template bindings. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@202087 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/ChangeLog | 8 +++++++ gcc/cp/error.c | 73 +++++++++++++++++++++++++++++++++++--------------------- 2 files changed, 54 insertions(+), 27 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index bf49198..f848b81 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +2013-08-29 Adam Butcher + + * error.c (dump_lambda_function): New function, dependent on ... + (dump_substitution): ... this new function, factored out of ... + (subst_to_string): ... here and ... + (dump_function_decl): ... here. Updated to early-out with call to + dump_lambda_function after determining template bindings. + 2013-08-28 Paolo Carlini PR c++/58255 diff --git a/gcc/cp/error.c b/gcc/cp/error.c index c82a0ce..af71000 100644 --- a/gcc/cp/error.c +++ b/gcc/cp/error.c @@ -1363,6 +1363,47 @@ find_typenames (tree t) return ft.typenames; } +/* Output the "[with ...]" clause for a template instantiation T iff + TEMPLATE_PARMS, TEMPLATE_ARGS and FLAGS are suitable. T may be NULL if + formatting a deduction/substitution diagnostic rather than an + instantiation. */ + +static void +dump_substitution (cxx_pretty_printer *pp, + tree t, tree template_parms, tree template_args, + int flags) +{ + if (template_parms != NULL_TREE && template_args != NULL_TREE + && !(flags & TFF_NO_TEMPLATE_BINDINGS)) + { + vec *typenames = t ? find_typenames (t) : NULL; + pp_cxx_whitespace (pp); + pp_cxx_left_bracket (pp); + pp->translate_string ("with"); + pp_cxx_whitespace (pp); + dump_template_bindings (pp, template_parms, template_args, typenames); + pp_cxx_right_bracket (pp); + } +} + +/* Dump the lambda function FN including its 'mutable' qualifier and any + template bindings. */ + +static void +dump_lambda_function (cxx_pretty_printer *pp, + tree fn, tree template_parms, tree template_args, + int flags) +{ + /* A lambda's signature is essentially its "type". */ + dump_type (pp, DECL_CONTEXT (fn), flags); + if (!(TYPE_QUALS (class_of_this_parm (TREE_TYPE (fn))) & TYPE_QUAL_CONST)) + { + pp->padding = pp_before; + pp_c_ws_string (pp, "mutable"); + } + dump_substitution (pp, fn, template_parms, template_args, flags); +} + /* Pretty print a function decl. There are several ways we want to print a function declaration. The TFF_ bits in FLAGS tells us how to behave. As error can only apply the '#' flag once to give 0 and 1 for V, there @@ -1379,15 +1420,6 @@ dump_function_decl (cxx_pretty_printer *pp, tree t, int flags) int show_return = flags & TFF_RETURN_TYPE || flags & TFF_DECL_SPECIFIERS; int do_outer_scope = ! (flags & TFF_UNQUALIFIED_NAME); tree exceptions; - vec *typenames = NULL; - - if (DECL_NAME (t) && LAMBDA_FUNCTION_P (t)) - { - /* A lambda's signature is essentially its "type", so defer. */ - gcc_assert (LAMBDA_TYPE_P (DECL_CONTEXT (t))); - dump_type (pp, DECL_CONTEXT (t), flags); - return; - } flags &= ~(TFF_UNQUALIFIED_NAME | TFF_TEMPLATE_NAME); if (TREE_CODE (t) == TEMPLATE_DECL) @@ -1409,10 +1441,12 @@ dump_function_decl (cxx_pretty_printer *pp, tree t, int flags) { template_parms = DECL_TEMPLATE_PARMS (tmpl); t = tmpl; - typenames = find_typenames (t); } } + if (DECL_NAME (t) && LAMBDA_FUNCTION_P (t)) + return dump_lambda_function (pp, t, template_parms, template_args, flags); + fntype = TREE_TYPE (t); parmtypes = FUNCTION_FIRST_USER_PARMTYPE (t); @@ -1476,17 +1510,7 @@ dump_function_decl (cxx_pretty_printer *pp, tree t, int flags) if (show_return) dump_type_suffix (pp, TREE_TYPE (fntype), flags); - /* If T is a template instantiation, dump the parameter binding. */ - if (template_parms != NULL_TREE && template_args != NULL_TREE - && !(flags & TFF_NO_TEMPLATE_BINDINGS)) - { - pp_cxx_whitespace (pp); - pp_cxx_left_bracket (pp); - pp_cxx_ws_string (pp, M_("with")); - pp_cxx_whitespace (pp); - dump_template_bindings (pp, template_parms, template_args, typenames); - pp_cxx_right_bracket (pp); - } + dump_substitution (pp, t, template_parms, template_args, flags); } else if (template_args) { @@ -2950,12 +2974,7 @@ subst_to_string (tree p) reinit_cxx_pp (); dump_template_decl (cxx_pp, TREE_PURPOSE (p), flags); - pp_cxx_whitespace (cxx_pp); - pp_cxx_left_bracket (cxx_pp); - pp_cxx_ws_string (cxx_pp, M_("with")); - pp_cxx_whitespace (cxx_pp); - dump_template_bindings (cxx_pp, tparms, targs, NULL); - pp_cxx_right_bracket (cxx_pp); + dump_substitution (cxx_pp, NULL, tparms, targs, /*flags=*/0); return pp_ggc_formatted_text (cxx_pp); }