Patchwork C++ PATCH to lambda printing in diagnostics

login
register
mail settings
Submitter Jason Merrill
Date April 22, 2013, 8:25 p.m.
Message ID <51759CBC.2090904@redhat.com>
Download mbox | patch
Permalink /patch/238660/
State New
Headers show

Comments

Jason Merrill - April 22, 2013, 8:25 p.m.
For this testcase, the patch changes output like 
"f.main()::__lambda0::__x" to "f.main()::<lambda()>::<x capture>".

Tested x86_64-pc-linux-gnu, applying to trunk.
Gabriel Dos Reis - April 22, 2013, 8:58 p.m.
On Mon, Apr 22, 2013 at 3:25 PM, Jason Merrill <jason@redhat.com> wrote:
> For this testcase, the patch changes output like "f.main()::__lambda0::__x"
> to "f.main()::<lambda()>::<x capture>".

Agreed.

>
> Tested x86_64-pc-linux-gnu, applying to trunk.

Patch

commit 22f4e8dfe343bfee35abf9ca0dc884342e343557
Author: Jason Merrill <jason@redhat.com>
Date:   Thu Apr 18 14:22:08 2013 +0100

    	* error.c (dump_aggr_type): Fix lambda detection.
    	(dump_simple_decl): Pretty-print capture field.

diff --git a/gcc/cp/error.c b/gcc/cp/error.c
index 6bac7ec..3206342 100644
--- a/gcc/cp/error.c
+++ b/gcc/cp/error.c
@@ -656,7 +656,7 @@  dump_aggr_type (tree t, int flags)
       else
 	pp_printf (pp_base (cxx_pp), M_("<anonymous %s>"), variety);
     }
-  else if (LAMBDA_TYPE_P (name))
+  else if (LAMBDA_TYPE_P (t))
     {
       /* A lambda's "type" is essentially its signature.  */
       pp_string (cxx_pp, M_("<lambda"));
@@ -933,7 +933,16 @@  dump_simple_decl (tree t, tree type, int flags)
       && TEMPLATE_PARM_PARAMETER_PACK (DECL_INITIAL (t)))
     pp_string (cxx_pp, "...");
   if (DECL_NAME (t))
-    dump_decl (DECL_NAME (t), flags);
+    {
+      if (DECL_CLASS_SCOPE_P (t) && LAMBDA_TYPE_P (DECL_CONTEXT (t)))
+	{
+	  pp_character (cxx_pp, '<');
+	  pp_string (cxx_pp, IDENTIFIER_POINTER (DECL_NAME (t)) + 2);
+	  pp_string (cxx_pp, " capture>");
+	}
+      else
+	dump_decl (DECL_NAME (t), flags);
+    }
   else
     pp_string (cxx_pp, M_("<anonymous>"));
   if (flags & TFF_DECL_SPECIFIERS)
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-diag1.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-diag1.C
new file mode 100644
index 0000000..0113cdf
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-diag1.C
@@ -0,0 +1,8 @@ 
+// { dg-require-effective-target c++11 }
+
+int main()
+{
+  int x;
+  auto f = [x]{ };
+  f.__x.foo;			// { dg-message "<lambda\\(\\)>::<x capture>" }
+}