diff options
author | Jason Merrill <jason@redhat.com> | 2010-06-29 20:51:44 -0400 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 2010-06-29 20:51:44 -0400 |
commit | d758e847c4ce6eda350809463cd87307c7e9c19c (patch) | |
tree | 232413e607b8465ed633e240d607739a6cbba07c /gcc/cp/tree.c | |
parent | 54ca9930b79c8f759919fdbe671ff24ce4141b0c (diff) | |
download | gcc-d758e847c4ce6eda350809463cd87307c7e9c19c.zip gcc-d758e847c4ce6eda350809463cd87307c7e9c19c.tar.gz gcc-d758e847c4ce6eda350809463cd87307c7e9c19c.tar.bz2 |
Enable implicitly declared move constructor/operator= (N3053).
gcc/cp/
* class.c (add_implicitly_declared_members): A class with no
explicitly declared copy or move constructor gets both declared
implicitly, and similarly for operator=.
(check_bases): A type with no copy ctor does not inhibit
a const copy ctor in a derived class.
(check_field_decl): Likewise.
(check_bases_and_members): A nonexistent copy ctor/op= is non-trivial.
* tree.c (type_has_nontrivial_copy_init): Adjust semantics.
(trivially_copyable_p): Likewise.
* call.c (convert_like_real): Use type_has_nontrivial_copy_init.
* class.c (finish_struct_bits): Likewise.
* tree.c (build_target_expr_with_type): Likewise.
* typeck2.c (store_init_value): Likewise.
libstdc++-v3/
* include/bits/unordered_map.h: Explicitly default copy constructors.
* include/bits/unordered_set.h: Likewise.
From-SVN: r161582
Diffstat (limited to 'gcc/cp/tree.c')
-rw-r--r-- | gcc/cp/tree.c | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index 3367a09..6d1ff10 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -479,7 +479,7 @@ build_target_expr_with_type (tree init, tree type) if (TREE_CODE (init) == TARGET_EXPR) return init; - else if (CLASS_TYPE_P (type) && !TYPE_HAS_TRIVIAL_COPY_CTOR (type) + else if (CLASS_TYPE_P (type) && type_has_nontrivial_copy_init (type) && !VOID_TYPE_P (TREE_TYPE (init)) && TREE_CODE (init) != COND_EXPR && TREE_CODE (init) != CONSTRUCTOR @@ -497,7 +497,8 @@ build_target_expr_with_type (tree init, tree type) /* Like the above function, but without the checking. This function should only be used by code which is deliberately trying to subvert the type - system, such as call_builtin_trap. */ + system, such as call_builtin_trap. Or build_over_call, to avoid + infinite recursion. */ tree force_target_expr (tree type, tree init) @@ -2368,7 +2369,9 @@ type_has_nontrivial_default_init (const_tree t) return 0; } -/* Returns true iff copying an object of type T is non-trivial. */ +/* Returns true iff copying an object of type T (including via move + constructor) is non-trivial. That is, T has no non-trivial copy + constructors and no non-trivial move constructors. */ bool type_has_nontrivial_copy_init (const_tree t) @@ -2376,7 +2379,12 @@ type_has_nontrivial_copy_init (const_tree t) t = strip_array_types (CONST_CAST_TREE (t)); if (CLASS_TYPE_P (t)) - return TYPE_HAS_COMPLEX_COPY_CTOR (t); + { + gcc_assert (COMPLETE_TYPE_P (t)); + return ((TYPE_HAS_COPY_CTOR (t) + && TYPE_HAS_COMPLEX_COPY_CTOR (t)) + || TYPE_HAS_COMPLEX_MOVE_CTOR (t)); + } else return 0; } @@ -2390,8 +2398,12 @@ trivially_copyable_p (const_tree t) t = strip_array_types (CONST_CAST_TREE (t)); if (CLASS_TYPE_P (t)) - return (TYPE_HAS_TRIVIAL_COPY_CTOR (t) - && TYPE_HAS_TRIVIAL_COPY_ASSIGN (t) + return ((!TYPE_HAS_COPY_CTOR (t) + || !TYPE_HAS_COMPLEX_COPY_CTOR (t)) + && !TYPE_HAS_COMPLEX_MOVE_CTOR (t) + && (!TYPE_HAS_COPY_ASSIGN (t) + || !TYPE_HAS_COMPLEX_COPY_ASSIGN (t)) + && !TYPE_HAS_COMPLEX_MOVE_ASSIGN (t) && TYPE_HAS_TRIVIAL_DESTRUCTOR (t)); else return scalarish_type_p (t); |