From 0e53a276bc87edde32d88697d27eb38ffb8805ad Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Mon, 20 Feb 2017 13:18:30 -0500 Subject: [PATCH] PR c++/78139 - destructor needed by new-expression * call.c (build_special_member_call): Use tf_no_cleanup. From-SVN: r245612 --- gcc/cp/ChangeLog | 3 +++ gcc/cp/call.c | 8 +++++++- gcc/testsuite/g++.dg/init/new48.C | 18 ++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/init/new48.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index b5def8cbb53..385c509fb97 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,8 @@ 2017-02-19 Jason Merrill + PR c++/78139 - destructor needed by new-expression + * call.c (build_special_member_call): Use tf_no_cleanup. + PR c++/78282 - auto template and pack expansion * pt.c (find_parameter_packs_r): Don't walk into the type of templates other than template template-parameters. diff --git a/gcc/cp/call.c b/gcc/cp/call.c index d6d3a8f61d9..93fae0d15b6 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -8356,9 +8356,15 @@ build_special_member_call (tree instance, tree name, vec **args, /* FIXME P0135 doesn't say how to handle direct initialization from a type with a suitable conversion operator. Let's handle it like copy-initialization, but allowing explict conversions. */ + tsubst_flags_t sub_complain = tf_warning; + if (!is_dummy_object (instance)) + /* If we're using this to initialize a non-temporary object, don't + require the destructor to be accessible. */ + sub_complain |= tf_no_cleanup; if (!reference_related_p (class_type, TREE_TYPE (arg))) arg = perform_implicit_conversion_flags (class_type, arg, - tf_warning, flags); + sub_complain, + flags); if ((TREE_CODE (arg) == TARGET_EXPR || TREE_CODE (arg) == CONSTRUCTOR) && (same_type_ignoring_top_level_qualifiers_p diff --git a/gcc/testsuite/g++.dg/init/new48.C b/gcc/testsuite/g++.dg/init/new48.C new file mode 100644 index 00000000000..528a582ea0e --- /dev/null +++ b/gcc/testsuite/g++.dg/init/new48.C @@ -0,0 +1,18 @@ +// PR c++/78139 + +struct A +{ + A(int); +private: + ~A(); +}; + +struct B +{ + B(void*); +}; + +int main() +{ + B(new A(42)); +} -- 2.30.2