From d331c5f10d5e6c9f41a24ff7cb7a8c6493790885 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Thu, 21 Feb 2019 20:47:43 +0000 Subject: [PATCH] PR libstdc++/89416 fix __is_move_insertable trait The common base class for __is_move_insertable and __is_copy_insertable instantiates both the copy and move tests, when only one is needed. The unneeded one might cause errors outside the immediate context. The solution used in this patch is to replace them with alias templates, which will only be instantiated as needed. PR libstdc++/89416 * include/bits/alloc_traits.h (__is_alloc_insertable_impl): Replace class template with class. Replace move and copy member types with member alias templates, so they are only instantiated when needed. (__is_copy_insertable, __is_move_insertable): Adjust base class. * testsuite/23_containers/vector/modifiers/push_back/89130.cc: Enable test for C++11/14/17 as well. * testsuite/23_containers/vector/modifiers/push_back/89416.cc: New test. From-SVN: r269075 --- libstdc++-v3/ChangeLog | 12 +++++ libstdc++-v3/include/bits/alloc_traits.h | 43 +++++++++--------- .../vector/modifiers/push_back/89130.cc | 3 +- .../vector/modifiers/push_back/89416.cc | 44 +++++++++++++++++++ 4 files changed, 78 insertions(+), 24 deletions(-) create mode 100644 libstdc++-v3/testsuite/23_containers/vector/modifiers/push_back/89416.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index bd38976a0f6..fab28f42079 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,15 @@ +2019-02-21 Jonathan Wakely + + PR libstdc++/89416 + * include/bits/alloc_traits.h (__is_alloc_insertable_impl): Replace + class template with class. Replace move and copy member types with + member alias templates, so they are only instantiated when needed. + (__is_copy_insertable, __is_move_insertable): Adjust base class. + * testsuite/23_containers/vector/modifiers/push_back/89130.cc: Enable + test for C++11/14/17 as well. + * testsuite/23_containers/vector/modifiers/push_back/89416.cc: New + test. + 2019-02-20 Jakub Jelinek PR libstdc++/89402 diff --git a/libstdc++-v3/include/bits/alloc_traits.h b/libstdc++-v3/include/bits/alloc_traits.h index 3b0c16fbf64..71892cbfaba 100644 --- a/libstdc++-v3/include/bits/alloc_traits.h +++ b/libstdc++-v3/include/bits/alloc_traits.h @@ -576,33 +576,32 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __do_alloc_on_swap(__one, __two, __pocs()); } - template - class __is_alloc_insertable_impl - { - using _Traits = allocator_traits<_Alloc>; - using value_type = typename _Traits::value_type; - - template, - typename - = decltype(_Traits::construct(std::declval<_Alloc&>(), - std::declval<_Tp*>(), - std::declval<_Up>()))> - static true_type - _M_select(int); + class __is_alloc_insertable_impl + { + template, + typename = decltype(allocator_traits<_Alloc>::construct( + std::declval<_Alloc&>(), std::declval<_Tp*>(), + std::declval<_Up>()))> + static true_type + _M_select(int); + + template + static false_type + _M_select(...); - template - static false_type - _M_select(...); + protected: + template + using copy = decltype(_M_select<_Alloc, const _Tp&>(0)); - public: - using copy = decltype(_M_select(0)); - using move = decltype(_M_select(0)); - }; + template + using move = decltype(_M_select<_Alloc, _Tp>(0)); + }; // true if _Alloc::value_type is CopyInsertable into containers using _Alloc template struct __is_copy_insertable - : __is_alloc_insertable_impl<_Alloc>::copy + : __is_alloc_insertable_impl::template copy<_Alloc> { }; // std::allocator<_Tp> just requires CopyConstructible @@ -614,7 +613,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // true if _Alloc::value_type is MoveInsertable into containers using _Alloc template struct __is_move_insertable - : __is_alloc_insertable_impl<_Alloc>::move + : __is_alloc_insertable_impl::template move<_Alloc> { }; // std::allocator<_Tp> just requires MoveConstructible diff --git a/libstdc++-v3/testsuite/23_containers/vector/modifiers/push_back/89130.cc b/libstdc++-v3/testsuite/23_containers/vector/modifiers/push_back/89130.cc index 54b3f53069b..1a34f3e25d3 100644 --- a/libstdc++-v3/testsuite/23_containers/vector/modifiers/push_back/89130.cc +++ b/libstdc++-v3/testsuite/23_containers/vector/modifiers/push_back/89130.cc @@ -15,8 +15,7 @@ // with this library; see the file COPYING3. If not see // . -// { dg-options "-std=gnu++2a" } -// { dg-do compile { target c++2a } } +// { dg-do compile { target c++11 } } #include diff --git a/libstdc++-v3/testsuite/23_containers/vector/modifiers/push_back/89416.cc b/libstdc++-v3/testsuite/23_containers/vector/modifiers/push_back/89416.cc new file mode 100644 index 00000000000..b1077611887 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/modifiers/push_back/89416.cc @@ -0,0 +1,44 @@ +// Copyright (C) 2019 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 +// . + +// { dg-do compile { target c++11 } } + +// PR libstdc++/89416 + +#include + +template + struct Alloc : std::allocator + { + using std::allocator::allocator; + + template + struct rebind { using other = Alloc; }; + }; + +struct X +{ + X(int); + X(X&&); +}; + +void test01() +{ + std::vector> V; + V.push_back(X(1)); + V.emplace_back(1); +} -- 2.30.2