From fb334765e2ab959fcf3630e3c4a31ba1cc01a0f2 Mon Sep 17 00:00:00 2001 From: Ville Voutilainen Date: Mon, 9 May 2016 14:03:36 +0300 Subject: [PATCH] Avoid endless run-time recursion for copying single-element tuples where the... Avoid endless run-time recursion for copying single-element tuples where the element type is by-value constructible from any type. * include/std/tuple (_NotSameTuple): New. * include/std/tuple (tuple(_UElements&&...): Use it. * testsuite/20_util/tuple/cons/element_accepts_anything_byval.cc: New. From-SVN: r236025 --- libstdc++-v3/ChangeLog | 9 ++++++ libstdc++-v3/include/std/tuple | 23 ++++++++++++-- .../cons/element_accepts_anything_byval.cc | 30 +++++++++++++++++++ 3 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 libstdc++-v3/testsuite/20_util/tuple/cons/element_accepts_anything_byval.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index cda02f4d2e3..6f4ae5f4950 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,12 @@ +2016-05-09 Ville Voutilainen + + Avoid endless run-time recursion for copying single-element + tuples where the element type is by-value constructible + from any type. + * include/std/tuple (_NotSameTuple): New. + * include/std/tuple (tuple(_UElements&&...): Use it. + * testsuite/20_util/tuple/cons/element_accepts_anything_byval.cc: New. + 2016-05-09 Jonathan Wakely PR libstdc++/71004 diff --git a/libstdc++-v3/include/std/tuple b/libstdc++-v3/include/std/tuple index 53f318455be..7522e435184 100644 --- a/libstdc++-v3/include/std/tuple +++ b/libstdc++-v3/include/std/tuple @@ -500,6 +500,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __not_> >::value; } + template + static constexpr bool _NotSameTuple() + { + return __not_, + typename remove_const< + typename remove_reference<_UElements...>::type + >::type>>::value; + } }; template @@ -534,6 +542,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return true; } + template + static constexpr bool _NotSameTuple() + { + return true; + } }; /// Primary class template, tuple @@ -611,7 +624,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _Elements...>; template::template + enable_if< + _TC::template + _NotSameTuple<_UElements...>() + && _TMC<_UElements...>::template _MoveConstructibleTuple<_UElements...>() && _TMC<_UElements...>::template _ImplicitlyMoveConvertibleTuple<_UElements...>() @@ -621,7 +637,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : _Inherited(std::forward<_UElements>(__elements)...) { } template::template + enable_if< + _TC::template + _NotSameTuple<_UElements...>() + && _TMC<_UElements...>::template _MoveConstructibleTuple<_UElements...>() && !_TMC<_UElements...>::template _ImplicitlyMoveConvertibleTuple<_UElements...>() diff --git a/libstdc++-v3/testsuite/20_util/tuple/cons/element_accepts_anything_byval.cc b/libstdc++-v3/testsuite/20_util/tuple/cons/element_accepts_anything_byval.cc new file mode 100644 index 00000000000..fe9bea678a4 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/tuple/cons/element_accepts_anything_byval.cc @@ -0,0 +1,30 @@ +// Copyright (C) 2016 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +using namespace std; + +struct Something { + Something() { } + template Something(T) { } +}; + +int main() { + tuple t1; + tuple t2 = t1; +} + -- 2.30.2