aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/cp-tree.h
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2021-01-13 13:27:06 -0500
committerJason Merrill <jason@redhat.com>2021-01-15 13:57:01 -0500
commitd75199f782348bfc401f925b60f33ffc9822b7cc (patch)
treea1f67748fa7024d5816a2133f7e9310101d70f0a /gcc/cp/cp-tree.h
parent424deca72b63e644cbc975cbc2fdda5248449bcb (diff)
downloadgcc-d75199f782348bfc401f925b60f33ffc9822b7cc.zip
gcc-d75199f782348bfc401f925b60f33ffc9822b7cc.tar.gz
gcc-d75199f782348bfc401f925b60f33ffc9822b7cc.tar.bz2
c++: Avoid redundant copy in {} init [PR98642]
Here, initializing from { } implies a call to the default constructor for base. We were then seeing that we're initializing a base subobject, so we tried to copy the result of that call. This is clearly wrong; we should initialize the base directly from its default constructor. This patch does a lot of refactoring of unsafe_copy_elision_p and adds make_safe_copy_elision that will also try to do the base constructor rewriting from the last patch. gcc/cp/ChangeLog: PR c++/98642 * call.c (unsafe_return_slot_p): Return int. (init_by_return_slot_p): Split out from... (unsafe_copy_elision_p): ...here. (unsafe_copy_elision_p_opt): New name for old meaning. (build_over_call): Adjust. (make_safe_copy_elision): New. * typeck2.c (split_nonconstant_init_1): Elide copy from safe list-initialization. * cp-tree.h: Adjust. gcc/testsuite/ChangeLog: PR c++/98642 * g++.dg/cpp1z/elide5.C: New test.
Diffstat (limited to 'gcc/cp/cp-tree.h')
-rw-r--r--gcc/cp/cp-tree.h3
1 files changed, 2 insertions, 1 deletions
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index e7b46b7..51139f4 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -6471,7 +6471,8 @@ extern bool is_std_init_list (tree);
extern bool is_list_ctor (tree);
extern void validate_conversion_obstack (void);
extern void mark_versions_used (tree);
-extern bool unsafe_return_slot_p (tree);
+extern int unsafe_return_slot_p (tree);
+extern bool make_safe_copy_elision (tree, tree);
extern bool cp_warn_deprecated_use (tree, tsubst_flags_t = tf_warning_or_error);
extern void cp_warn_deprecated_use_scopes (tree);
extern tree get_function_version_dispatcher (tree);