diff options
author | ville <ville@138bc75d-0d04-0410-961f-82ee72b054a4> | 2015-09-25 16:41:45 +0000 |
---|---|---|
committer | ville <ville@138bc75d-0d04-0410-961f-82ee72b054a4> | 2015-09-25 16:41:45 +0000 |
commit | 63e26b218b009b1cec13faa237b6e10cf347a078 (patch) | |
tree | 4b6be450261dddabdc4c78c3e479be2e192f2ee6 /libstdc++-v3/testsuite | |
parent | a6871bda07973b01bb6472dbd4cac03339cce8e2 (diff) | |
download | gcc-63e26b218b009b1cec13faa237b6e10cf347a078.tar.gz |
Avoid creating dangling references in case of nested tuples
for tuple constructors that construct from other tuples.
2015-09-25 Ville Voutilainen <ville.voutilainen@gmail.com>
Avoid creating dangling references in case of nested tuples
for tuple constructors that construct from other tuples.
* include/std/tuple (_TC::_NonNestedTuple): New.
* include/std/tuple (tuple::_TNTC): New.
* include/std/tuple (tuple(const tuple<_UElements...>&),
tuple(tuple<_UElements...>&&): Use _TNTC.
* testsuite/20_util/tuple/cons/nested_tuple_construct.cc: New.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@228134 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/testsuite')
-rw-r--r-- | libstdc++-v3/testsuite/20_util/tuple/cons/nested_tuple_construct.cc | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/20_util/tuple/cons/nested_tuple_construct.cc b/libstdc++-v3/testsuite/20_util/tuple/cons/nested_tuple_construct.cc new file mode 100644 index 00000000000..32ef3cc0259 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/tuple/cons/nested_tuple_construct.cc @@ -0,0 +1,60 @@ +#include <string> +#include <tuple> +#include <testsuite_hooks.h> + +static std::string result; + +struct X { + int state; // this has to be here + X() { + result += "Def"; + } + + X(X const&) { + result += "Copy"; + } + + X(X&&) { + result += "Move"; + } + + ~X() { + result += "Dtor"; + } +}; + +void f() +{ + X v; + std::tuple<X> t1{v}; + std::tuple<std::tuple<X>&&> t2{std::move(t1)}; + std::tuple<std::tuple<X>> t3{std::move(t2)}; +} + +void f2() +{ + X v; + std::tuple<X> t1{std::move(v)}; + std::tuple<std::tuple<X>&&> t2{std::move(t1)}; + std::tuple<std::tuple<X>> t3{std::move(t2)}; +} + +void f3() +{ + std::tuple<X> t1{X{}}; + std::tuple<std::tuple<X>&&> t2{std::move(t1)}; + std::tuple<std::tuple<X>> t3{std::move(t2)}; +} + +int main() +{ + f(); + VERIFY(result == "DefCopyMoveDtorDtorDtor"); + result = ""; + f2(); + VERIFY(result == "DefMoveMoveDtorDtorDtor"); + result = ""; + f3(); + VERIFY(result == "DefMoveDtorMoveDtorDtor"); + result = ""; +} |