re PR c++/66542 ([C++11] Can create static variable of type that has deleted destructor)
authorJason Merrill <jason@redhat.com>
Tue, 23 Jun 2015 14:08:19 +0000 (10:08 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Tue, 23 Jun 2015 14:08:19 +0000 (10:08 -0400)
PR c++/66542
* decl.c (expand_static_init): Make sure the destructor is callable
here even if we have an initializer.

From-SVN: r224842

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

index 479044807efbc320eb9e50d5b9dfe9d009c4e84c..194d764469c5a68b4c8da46f930934228ca93e7a 100644 (file)
@@ -1,3 +1,9 @@
+2015-06-23  Jason Merrill  <jason@redhat.com>
+
+       PR c++/66542
+       * decl.c (expand_static_init): Make sure the destructor is callable
+       here even if we have an initializer.
+
 2015-06-04  Pierre-Marie de Rodat  <derodat@adacore.com>
 
        * lang-specs.h: Pass "-o %g.s" to cc1plus for headers even if
index c934ff930779c01c40edbddc6e2e5c13f80ee2e9..d14ffe218fc53cb077acf2c1e2aae4a5927bbced 100644 (file)
@@ -7163,12 +7163,12 @@ expand_static_init (tree decl, tree init)
   gcc_assert (TREE_STATIC (decl));
 
   /* Some variables require no dynamic initialization.  */
-  if (!init
-      && TYPE_HAS_TRIVIAL_DESTRUCTOR (TREE_TYPE (decl)))
+  if (TYPE_HAS_TRIVIAL_DESTRUCTOR (TREE_TYPE (decl)))
     {
       /* Make sure the destructor is callable.  */
       cxx_maybe_build_cleanup (decl, tf_warning_or_error);
-      return;
+      if (!init)
+       return;
     }
 
   if (DECL_THREAD_LOCAL_P (decl) && DECL_GNU_TLS_P (decl)
diff --git a/gcc/testsuite/g++.dg/cpp0x/deleted12.C b/gcc/testsuite/g++.dg/cpp0x/deleted12.C
new file mode 100644 (file)
index 0000000..770bb9c
--- /dev/null
@@ -0,0 +1,10 @@
+// PR c++/66542
+// { dg-do compile { target c++11 } }
+
+struct A
+{
+  A() {}
+  ~A() = delete;               // { dg-message "declared here" }
+};
+
+static A a;                    // { dg-error "deleted" }