diff options
author | jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4> | 2010-06-30 00:51:44 +0000 |
---|---|---|
committer | jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4> | 2010-06-30 00:51:44 +0000 |
commit | bde2eab67c0f63e6dcafc495585ee57d7d810adf (patch) | |
tree | 232413e607b8465ed633e240d607739a6cbba07c /gcc/cp/class.c | |
parent | 4973dd77b950e66499d7df25595f714609a69f7c (diff) | |
download | gcc-bde2eab67c0f63e6dcafc495585ee57d7d810adf.tar.gz |
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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@161582 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/cp/class.c')
-rw-r--r-- | gcc/cp/class.c | 40 |
1 files changed, 25 insertions, 15 deletions
diff --git a/gcc/cp/class.c b/gcc/cp/class.c index 031a4ea79c3..a2ed86334b5 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -1282,7 +1282,8 @@ check_bases (tree t, assignment operators that take const references, then the derived class cannot have such a member automatically generated. */ - if (! TYPE_HAS_CONST_COPY_CTOR (basetype)) + if (TYPE_HAS_COPY_CTOR (basetype) + && ! TYPE_HAS_CONST_COPY_CTOR (basetype)) *cant_have_const_ctor_p = 1; if (TYPE_HAS_COPY_ASSIGN (basetype) && !TYPE_HAS_CONST_COPY_ASSIGN (basetype)) @@ -1312,8 +1313,10 @@ check_bases (tree t, TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t) |= TYPE_HAS_NONTRIVIAL_DESTRUCTOR (basetype); TYPE_HAS_COMPLEX_COPY_ASSIGN (t) - |= TYPE_HAS_COMPLEX_COPY_ASSIGN (basetype); - TYPE_HAS_COMPLEX_COPY_CTOR (t) |= TYPE_HAS_COMPLEX_COPY_CTOR (basetype); + |= (TYPE_HAS_COMPLEX_COPY_ASSIGN (basetype) + || !TYPE_HAS_COPY_ASSIGN (basetype)); + TYPE_HAS_COMPLEX_COPY_CTOR (t) |= (TYPE_HAS_COMPLEX_COPY_CTOR (basetype) + || !TYPE_HAS_COPY_CTOR (basetype)); TYPE_HAS_COMPLEX_MOVE_ASSIGN (t) |= TYPE_HAS_COMPLEX_MOVE_ASSIGN (basetype); TYPE_HAS_COMPLEX_MOVE_CTOR (t) |= TYPE_HAS_COMPLEX_MOVE_CTOR (basetype); @@ -1545,7 +1548,8 @@ finish_struct_bits (tree t) mode to be BLKmode, and force its TREE_ADDRESSABLE bit to be nonzero. This will cause it to be passed by invisible reference and prevent it from being returned in a register. */ - if (! TYPE_HAS_TRIVIAL_COPY_CTOR (t) || TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)) + if (type_has_nontrivial_copy_init (t) + || TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)) { tree variants; DECL_MODE (TYPE_MAIN_DECL (t)) = BLKmode; @@ -2647,27 +2651,28 @@ add_implicitly_declared_members (tree t, If a class definition does not explicitly declare a copy constructor, one is declared implicitly. */ - if (! TYPE_HAS_COPY_CTOR (t) && ! TYPE_FOR_JAVA (t)) + if (! TYPE_HAS_COPY_CTOR (t) && ! TYPE_FOR_JAVA (t) + && !type_has_move_constructor (t)) { TYPE_HAS_COPY_CTOR (t) = 1; TYPE_HAS_CONST_COPY_CTOR (t) = !cant_have_const_cctor; CLASSTYPE_LAZY_COPY_CTOR (t) = 1; + if (cxx_dialect >= cxx0x) + CLASSTYPE_LAZY_MOVE_CTOR (t) = 1; } - /* Currently only lambdas get a lazy move ctor, but N3053 adds them for - other classes. */ - if (LAMBDA_TYPE_P (t)) - CLASSTYPE_LAZY_MOVE_CTOR (t) = 1; - /* If there is no assignment operator, one will be created if and when it is needed. For now, just record whether or not the type of the parameter to the assignment operator will be a const or non-const reference. */ - if (!TYPE_HAS_COPY_ASSIGN (t) && !TYPE_FOR_JAVA (t)) + if (!TYPE_HAS_COPY_ASSIGN (t) && !TYPE_FOR_JAVA (t) + && !type_has_move_assign (t)) { TYPE_HAS_COPY_ASSIGN (t) = 1; TYPE_HAS_CONST_COPY_ASSIGN (t) = !cant_have_const_assignment; CLASSTYPE_LAZY_COPY_ASSIGN (t) = 1; + if (cxx_dialect >= cxx0x) + CLASSTYPE_LAZY_MOVE_ASSIGN (t) = 1; } /* We can't be lazy about declaring functions that might override @@ -2863,18 +2868,23 @@ check_field_decl (tree field, TYPE_NEEDS_CONSTRUCTING (t) |= TYPE_NEEDS_CONSTRUCTING (type); TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t) |= TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type); - TYPE_HAS_COMPLEX_COPY_ASSIGN (t) |= TYPE_HAS_COMPLEX_COPY_ASSIGN (type); - TYPE_HAS_COMPLEX_COPY_CTOR (t) |= TYPE_HAS_COMPLEX_COPY_CTOR (type); + TYPE_HAS_COMPLEX_COPY_ASSIGN (t) + |= (TYPE_HAS_COMPLEX_COPY_ASSIGN (type) + || !TYPE_HAS_COPY_ASSIGN (type)); + TYPE_HAS_COMPLEX_COPY_CTOR (t) |= (TYPE_HAS_COMPLEX_COPY_CTOR (type) + || !TYPE_HAS_COPY_CTOR (type)); TYPE_HAS_COMPLEX_MOVE_ASSIGN (t) |= TYPE_HAS_COMPLEX_MOVE_ASSIGN (type); TYPE_HAS_COMPLEX_MOVE_CTOR (t) |= TYPE_HAS_COMPLEX_MOVE_CTOR (type); TYPE_HAS_COMPLEX_DFLT (t) |= (!TYPE_HAS_DEFAULT_CONSTRUCTOR (type) || TYPE_HAS_COMPLEX_DFLT (type)); } - if (!TYPE_HAS_CONST_COPY_CTOR (type)) + if (TYPE_HAS_COPY_CTOR (type) + && !TYPE_HAS_CONST_COPY_CTOR (type)) *cant_have_const_ctor = 1; - if (!TYPE_HAS_CONST_COPY_ASSIGN (type)) + if (TYPE_HAS_COPY_ASSIGN (type) + && !TYPE_HAS_CONST_COPY_ASSIGN (type)) *no_const_asn_ref = 1; } if (DECL_INITIAL (field) != NULL_TREE) |