diff mbox

C++ PATCH for c++/51818 (wrong mangling with NSDMI and lambda)

Message ID 4F0DEF05.6010500@redhat.com
State New
Headers show

Commit Message

Jason Merrill Jan. 11, 2012, 8:20 p.m. UTC
In this testcase we were omitting the mangling scope for a lambda 
defined in an NSDMI because we weren't using decl_mangling_context where 
needed.  After fixing that, we also needed to fix find_substitution to 
not treat A as a substitution for foo::bar.

Tested x86_64-pc-linux-gnu, applying to trunk since this is an ABI 
violation that occurs on code that was not previously accepted.
diff mbox

Patch

commit f055576d031b2521f3ba7c4533556b0651b22479
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Jan 11 14:37:49 2012 -0500

    	PR c++/51818
    	* mangle.c (find_substitution): A type is only a substitution
    	match if we're looking for a type.
    	(write_nested_name): Use decl_mangling_context.

diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c
index f4efa67..60b1870 100644
--- a/gcc/cp/mangle.c
+++ b/gcc/cp/mangle.c
@@ -615,7 +615,7 @@  find_substitution (tree node)
       /* NODE is a matched to a candidate if it's the same decl node or
 	 if it's the same type.  */
       if (decl == candidate
-	  || (TYPE_P (candidate) && type && TYPE_P (type)
+	  || (TYPE_P (candidate) && type && TYPE_P (node)
 	      && same_type_p (type, candidate))
 	  || NESTED_TEMPLATE_MATCH (node, candidate))
 	{
@@ -949,7 +949,7 @@  write_nested_name (const tree decl)
   else
     {
       /* No, just use <prefix>  */
-      write_prefix (CP_DECL_CONTEXT (decl));
+      write_prefix (decl_mangling_context (decl));
       write_unqualified_name (decl);
     }
   write_char ('E');
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-mangle3.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-mangle3.C
new file mode 100644
index 0000000..06913a1
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-mangle3.C
@@ -0,0 +1,15 @@ 
+// PR c++/51818
+// { dg-options -std=c++0x }
+// { dg-final { scan-assembler "_ZN1AC1IN3foo3barMUlvE_EEET_" } }
+
+struct A
+{
+  template <class T> A(T) { }
+};
+
+struct foo
+{
+  A bar = []{};
+};
+
+foo f;