In the case of a static anonymous union we have a decl with no DECL_NAME
(just a DECL_ASSEMBLER_NAME), and write_guarded_name shouldn't crash.
Tested x86_64-pc-linux-gnu, applying to trunk.
commit 0d626f236f9daf2891362c17db1220214ab0a64d
Author: Jason Merrill <ja...@redhat.com>
Date: Thu Jan 2 22:50:11 2014 -0500
PR c++/58965
* mangle.c (write_guarded_var_name): Handle null DECL_NAME.
diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c
index b3bcc12..d6650d3 100644
--- a/gcc/cp/mangle.c
+++ b/gcc/cp/mangle.c
@@ -3778,7 +3778,8 @@ mangle_conv_op_name_for_type (const tree type)
static void
write_guarded_var_name (const tree variable)
{
- if (strncmp (IDENTIFIER_POINTER (DECL_NAME (variable)), "_ZGR", 4) == 0)
+ if (DECL_NAME (variable)
+ && strncmp (IDENTIFIER_POINTER (DECL_NAME (variable)), "_ZGR", 4) == 0)
/* The name of a guard variable for a reference temporary should refer
to the reference, not the temporary. */
write_string (IDENTIFIER_POINTER (DECL_NAME (variable)) + 4);
diff --git a/gcc/testsuite/g++.dg/cpp0x/nsdmi-union3.C b/gcc/testsuite/g++.dg/cpp0x/nsdmi-union3.C
new file mode 100644
index 0000000..35f6509
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/nsdmi-union3.C
@@ -0,0 +1,10 @@
+// PR c++/58965
+// { dg-require-effective-target c++11 }
+
+void foo()
+{
+ static union
+ {
+ int i = i;
+ };
+}