From d4c9e7f92225d829ad1d18c950066cf99fc58cc7 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Tue, 23 Jun 2015 10:08:19 -0400 Subject: [PATCH] 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 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/decl.c | 6 +++--- gcc/testsuite/g++.dg/cpp0x/deleted12.C | 10 ++++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/deleted12.C 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" } -- 2.30.2