Commit fb334765 by Ville Voutilainen Committed by Ville Voutilainen

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
parent fc48633e
2016-05-09 Ville Voutilainen <ville.voutilainen@gmail.com>
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 <jwakely@redhat.com> 2016-05-09 Jonathan Wakely <jwakely@redhat.com>
PR libstdc++/71004 PR libstdc++/71004
......
...@@ -500,6 +500,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -500,6 +500,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
__not_<is_constructible<_Elements..., _SrcTuple>> __not_<is_constructible<_Elements..., _SrcTuple>>
>::value; >::value;
} }
template<typename... _UElements>
static constexpr bool _NotSameTuple()
{
return __not_<is_same<tuple<_Elements...>,
typename remove_const<
typename remove_reference<_UElements...>::type
>::type>>::value;
}
}; };
template<typename... _Elements> template<typename... _Elements>
...@@ -534,6 +542,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -534,6 +542,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ {
return true; return true;
} }
template<typename... _UElements>
static constexpr bool _NotSameTuple()
{
return true;
}
}; };
/// Primary class template, tuple /// Primary class template, tuple
...@@ -611,7 +624,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -611,7 +624,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_Elements...>; _Elements...>;
template<typename... _UElements, typename template<typename... _UElements, typename
enable_if<_TMC<_UElements...>::template enable_if<
_TC<sizeof...(_UElements) == 1, _Elements...>::template
_NotSameTuple<_UElements...>()
&& _TMC<_UElements...>::template
_MoveConstructibleTuple<_UElements...>() _MoveConstructibleTuple<_UElements...>()
&& _TMC<_UElements...>::template && _TMC<_UElements...>::template
_ImplicitlyMoveConvertibleTuple<_UElements...>() _ImplicitlyMoveConvertibleTuple<_UElements...>()
...@@ -621,7 +637,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -621,7 +637,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
: _Inherited(std::forward<_UElements>(__elements)...) { } : _Inherited(std::forward<_UElements>(__elements)...) { }
template<typename... _UElements, typename template<typename... _UElements, typename
enable_if<_TMC<_UElements...>::template enable_if<
_TC<sizeof...(_UElements) == 1, _Elements...>::template
_NotSameTuple<_UElements...>()
&& _TMC<_UElements...>::template
_MoveConstructibleTuple<_UElements...>() _MoveConstructibleTuple<_UElements...>()
&& !_TMC<_UElements...>::template && !_TMC<_UElements...>::template
_ImplicitlyMoveConvertibleTuple<_UElements...>() _ImplicitlyMoveConvertibleTuple<_UElements...>()
......
// 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
// <http://www.gnu.org/licenses/>.
#include <tuple>
using namespace std;
struct Something {
Something() { }
template <typename T> Something(T) { }
};
int main() {
tuple<Something> t1;
tuple<Something> t2 = t1;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment