semantics.c (finish_compound_literal): Don't put an array with a dtor in a static...
authorJason Merrill <jason@redhat.com>
Thu, 21 Apr 2011 04:28:32 +0000 (00:28 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Thu, 21 Apr 2011 04:28:32 +0000 (00:28 -0400)
* semantics.c (finish_compound_literal): Don't put an array
with a dtor in a static variable.

From-SVN: r172810

gcc/cp/ChangeLog
gcc/cp/semantics.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/initlist47.C [new file with mode: 0644]

index dcfa7e67a71ce05dbbfe61f95d54f9fa33e5ca84..965ee6ee73b7a462b3b34002aadc4188bb4f7eb3 100644 (file)
@@ -1,5 +1,8 @@
 2011-04-20  Jason Merrill  <jason@redhat.com>
 
+       * semantics.c (finish_compound_literal): Don't put an array
+       with a dtor in a static variable.
+
        * call.c (build_over_call): Handle trivial dtor.
 
        * search.c (lookup_fnfields_slot): Call complete_type.
index e9b19076ff195b961eecf41534cadbdc1368b146..7763ae00bf374ab48c02ee5fcc988c4f1a279e11 100644 (file)
@@ -2383,6 +2383,7 @@ finish_compound_literal (tree type, tree compound_literal,
      represent class temporaries with TARGET_EXPR so we elide copies.  */
   if ((!at_function_scope_p () || CP_TYPE_CONST_P (type))
       && TREE_CODE (type) == ARRAY_TYPE
+      && !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
       && initializer_constant_valid_p (compound_literal, type))
     {
       tree decl = create_temporary_var (type);
index 8fd021625ac6b95d50001ab37d4c744c15949366..07a0a6b3aedc475d1f2740a8bd56a30e6738a331 100644 (file)
@@ -1,5 +1,7 @@
 2011-04-20  Jason Merrill  <jason@redhat.com>
 
+       * g++.dg/cpp0x/initlist47.C: New.
+
        * g++.dg/init/dtor4.C: New.
 
 2011-04-20  Uros Bizjak  <ubizjak@gmail.com>
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist47.C b/gcc/testsuite/g++.dg/cpp0x/initlist47.C
new file mode 100644 (file)
index 0000000..b76fb58
--- /dev/null
@@ -0,0 +1,9 @@
+// { dg-options -std=c++0x }
+
+struct A { ~A() = delete; };   // { dg-error "declared" }
+
+int main()
+{
+  typedef const A cA[2];
+  cA{};                                // { dg-error "deleted" }
+}