Commit 1d7bc790 by Nathan Sidwell Committed by Nathan Sidwell

PR c++/78469 - defaulted ctor and inaccessible dtor

	PR c++/78469 - defaulted ctor and inaccessible dtor
	* cp-tree.h (tsubst_flags): Add tf_no_cleanup.
	* init.c (build_new_1): Pass tf_no_cleanup to build_value_init.
	* tree.c (build_target_expr): Check tf_no_cleanup.

	PR c++/78469
	* g++.dg/cpp0x/pr78469.C: New.

From-SVN: r244882
parent 3e4b91f2
2017-01-24 Nathan Sidwell <nathan@acm.org> 2017-01-24 Nathan Sidwell <nathan@acm.org>
PR c++/78469 - defaulted ctor and inaccessible dtor
* cp-tree.h (tsubst_flags): Add tf_no_cleanup.
* init.c (build_new_1): Pass tf_no_cleanup to build_value_init.
* tree.c (build_target_expr): Check tf_no_cleanup.
PR c++/79118 - anon-members and constexpr PR c++/79118 - anon-members and constexpr
* constexpr.c (cx_check_missing_mem_inits): Caller passes type not * constexpr.c (cx_check_missing_mem_inits): Caller passes type not
ctor decl. Recursively check anonymous members. ctor decl. Recursively check anonymous members.
......
...@@ -4786,6 +4786,8 @@ enum tsubst_flags { ...@@ -4786,6 +4786,8 @@ enum tsubst_flags {
substitution in fn_type_unification. */ substitution in fn_type_unification. */
tf_fndecl_type = 1 << 9, /* Substituting the type of a function tf_fndecl_type = 1 << 9, /* Substituting the type of a function
declaration. */ declaration. */
tf_no_cleanup = 1 << 10, /* Do not build a cleanup
(build_target_expr and friends) */
/* Convenient substitution flags combinations. */ /* Convenient substitution flags combinations. */
tf_warning_or_error = tf_warning | tf_error tf_warning_or_error = tf_warning | tf_error
}; };
......
...@@ -3262,8 +3262,10 @@ build_new_1 (vec<tree, va_gc> **placement, tree type, tree nelts, ...@@ -3262,8 +3262,10 @@ build_new_1 (vec<tree, va_gc> **placement, tree type, tree nelts,
} }
else if (explicit_value_init_p) else if (explicit_value_init_p)
{ {
/* Something like `new int()'. */ /* Something like `new int()'. NO_CLEANUP is needed so
tree val = build_value_init (type, complain); we don't try and build a (possibly ill-formed)
destructor. */
tree val = build_value_init (type, complain | tf_no_cleanup);
if (val == error_mark_node) if (val == error_mark_node)
return error_mark_node; return error_mark_node;
init_expr = build2 (INIT_EXPR, type, init_expr, val); init_expr = build2 (INIT_EXPR, type, init_expr, val);
......
...@@ -404,9 +404,15 @@ build_target_expr (tree decl, tree value, tsubst_flags_t complain) ...@@ -404,9 +404,15 @@ build_target_expr (tree decl, tree value, tsubst_flags_t complain)
|| useless_type_conversion_p (TREE_TYPE (decl), || useless_type_conversion_p (TREE_TYPE (decl),
TREE_TYPE (value))); TREE_TYPE (value)));
t = cxx_maybe_build_cleanup (decl, complain); if (complain & tf_no_cleanup)
if (t == error_mark_node) /* The caller is building a new-expr and does not need a cleanup. */
return error_mark_node; t = NULL_TREE;
else
{
t = cxx_maybe_build_cleanup (decl, complain);
if (t == error_mark_node)
return error_mark_node;
}
t = build4 (TARGET_EXPR, type, decl, value, t, NULL_TREE); t = build4 (TARGET_EXPR, type, decl, value, t, NULL_TREE);
if (EXPR_HAS_LOCATION (value)) if (EXPR_HAS_LOCATION (value))
SET_EXPR_LOCATION (t, EXPR_LOCATION (value)); SET_EXPR_LOCATION (t, EXPR_LOCATION (value));
......
2017-01-24 Nathan Sidwell <nathan@acm.org> 2017-01-24 Nathan Sidwell <nathan@acm.org>
PR c++/78469
* g++.dg/cpp0x/pr78469.C: New.
PR c++/79118 PR c++/79118
* g++.dg/cpp0x/pr79118.C: New. * g++.dg/cpp0x/pr79118.C: New.
......
// { dg-do compile { target c++11 } }
// PR78469, bogus error about inaccessible dtor.
struct no_destr {
no_destr() = default;
protected:
~no_destr() = default;
};
void *Foo ()
{
return new no_destr ();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment