From: Jason Merrill Date: Tue, 23 Jun 2015 14:08:19 +0000 (-0400) Subject: re PR c++/66542 ([C++11] Can create static variable of type that has deleted destructor) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=d4c9e7f92225d829ad1d18c950066cf99fc58cc7;p=gcc.git re PR c++/66542 ([C++11] Can create static variable of type that has deleted destructor) PR c++/66542 * decl.c (expand_static_init): Make sure the destructor is callable here even if we have an initializer. From-SVN: r224842 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 479044807ef..194d764469c 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2015-06-23 Jason Merrill + + 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 * lang-specs.h: Pass "-o %g.s" to cc1plus for headers even if diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index c934ff93077..d14ffe218fc 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -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 index 00000000000..770bb9c305a --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/deleted12.C @@ -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" }