diff mbox

[C++] Fix a C++ mangling ICE due to TRANSLATION_UNIT_DECL (PR c++/49276)

Message ID r9qiy9miel70ykxc7fnc9g6t.1307132012066@email.android.com
State New
Headers show

Commit Message

Jason Merrill June 3, 2011, 8:13 p.m. UTC
Ok.

Jakub Jelinek <jakub@redhat.com> wrote:

Hi!

This testcase got broken by the
http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=164719
changes, before that it really didn't matter at that spot
if DECL_CONTEXT or CP_DECL_CONTEXT is used, as write_prefix
immediately returns for both NULL and global_namespace.
But when DECL_CONTEXT is TRANSLATION_UNIT_DECL, we still want to call
write_prefix with NULL or global_namespace instead.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux,
ok for trunk/4.6?

2011-06-03  Jakub Jelinek  <jakub@redhat.com>

	PR c++/49276
	* mangle.c (write_nested_name): Use CP_DECL_CONTEXT instead of
	DECL_CONTEXT.

	* g++.dg/cpp0x/lambda/lambda-mangle2.C: New test.


	Jakub
diff mbox

Patch

--- gcc/cp/mangle.c.jj	2011-05-31 08:03:00.000000000 +0200
+++ gcc/cp/mangle.c	2011-06-03 15:47:42.000000000 +0200
@@ -1,6 +1,6 @@ 
 /* Name mangling for the 3.0 C++ ABI.
-   Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010
-   Free Software Foundation, Inc.
+   Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010,
+   2011  Free Software Foundation, Inc.
    Written by Alex Samuel <samuel@codesourcery.com>
 
    This file is part of GCC.
@@ -943,7 +943,7 @@  write_nested_name (const tree decl)
   else
     {
       /* No, just use <prefix>  */
-      write_prefix (DECL_CONTEXT (decl));
+      write_prefix (CP_DECL_CONTEXT (decl));
       write_unqualified_name (decl);
     }
   write_char ('E');
--- gcc/testsuite/g++.dg/cpp0x/lambda/lambda-mangle2.C.jj	2011-06-03 16:44:26.000000000 +0200
+++ gcc/testsuite/g++.dg/cpp0x/lambda/lambda-mangle2.C	2011-06-03 16:45:59.000000000 +0200
@@ -0,0 +1,21 @@ 
+// PR c++/49276
+// { dg-do compile }
+// { dg-options "-std=c++0x" }
+
+template <int N>
+struct F
+{
+  template <typename U> F (U);
+};
+
+struct S
+{
+  void foo (F <0> x = [] {}) {}
+};
+
+int
+main ()
+{
+  S s;
+  s.foo ();
+}