diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2017-01-12 17:28:36 +0000 |
---|---|---|
committer | Jonathan Wakely <redi@gcc.gnu.org> | 2017-01-12 17:28:36 +0000 |
commit | a1f009a65fd70df0962e0d5b94aba313520df357 (patch) | |
tree | cf31d11b0fdf99bd93175ef05c7d44353ea12594 | |
parent | 27282dadbfc2c0a23ca3a2c285b9a71e0e5376d8 (diff) | |
download | gcc-a1f009a65fd70df0962e0d5b94aba313520df357.zip gcc-a1f009a65fd70df0962e0d5b94aba313520df357.tar.gz gcc-a1f009a65fd70df0962e0d5b94aba313520df357.tar.bz2 |
PR77528 partially revert r244278 and define default constructors
PR libstdc++/77528
* include/bits/stl_queue.h (queue, priority_queue): Remove default
member-initializers and define default constructors as templates with
constraints.
* include/bits/stl_stack.h (stack): Likewise.
* testsuite/23_containers/priority_queue/requirements/constructible.cc:
New.
* testsuite/23_containers/priority_queue/requirements/
explicit_instantiation/1.cc: Test more instantiations.
* testsuite/23_containers/priority_queue/requirements/
explicit_instantiation/1_c++98.cc: Likewise.
* testsuite/23_containers/queue/requirements/constructible.cc: New.
* testsuite/23_containers/stack/requirements/constructible.cc: New.
From-SVN: r244374
8 files changed, 158 insertions, 22 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 7a70e25..8bf7d07 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,19 @@ 2017-01-12 Jonathan Wakely <jwakely@redhat.com> + PR libstdc++/77528 + * include/bits/stl_queue.h (queue, priority_queue): Remove default + member-initializers and define default constructors as templates with + constraints. + * include/bits/stl_stack.h (stack): Likewise. + * testsuite/23_containers/priority_queue/requirements/constructible.cc: + New. + * testsuite/23_containers/priority_queue/requirements/ + explicit_instantiation/1.cc: Test more instantiations. + * testsuite/23_containers/priority_queue/requirements/ + explicit_instantiation/1_c++98.cc: Likewise. + * testsuite/23_containers/queue/requirements/constructible.cc: New. + * testsuite/23_containers/stack/requirements/constructible.cc: New. + PR libstdc++/66284 * doc/xml/manual/intro.xml: Document LWG 2781 change. * doc/html/*: Regenerate. diff --git a/libstdc++-v3/include/bits/stl_queue.h b/libstdc++-v3/include/bits/stl_queue.h index 6417b30..3a52367 100644 --- a/libstdc++-v3/include/bits/stl_queue.h +++ b/libstdc++-v3/include/bits/stl_queue.h @@ -131,12 +131,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * of private: to allow derivation. But none of the other * containers allow for derivation. Odd.) */ - /// @c c is the underlying container. -#if __cplusplus >= 201103L - _Sequence c{}; -#else + /// @c c is the underlying container. _Sequence c; -#endif public: /** @@ -147,7 +143,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION queue(const _Sequence& __c = _Sequence()) : c(__c) { } #else - queue() = default; + template<typename _Seq = _Sequence, typename _Requires = typename + enable_if<is_default_constructible<_Seq>::value>::type> + queue() + : c() { } explicit queue(const _Sequence& __c) @@ -446,13 +445,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION protected: // See queue::c for notes on these names. -#if __cplusplus >= 201103L - _Sequence c{}; - _Compare comp{}; -#else - _Sequence c; + _Sequence c; _Compare comp; -#endif public: /** @@ -465,17 +459,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : c(__s), comp(__x) { std::make_heap(c.begin(), c.end(), comp); } #else - priority_queue() = default; + template<typename _Seq = _Sequence, typename _Requires = typename + enable_if<__and_<is_default_constructible<_Compare>, + is_default_constructible<_Seq>>::value>::type> + priority_queue() + : c(), comp() { } explicit - priority_queue(const _Compare& __x, - const _Sequence& __s) + priority_queue(const _Compare& __x, const _Sequence& __s) : c(__s), comp(__x) { std::make_heap(c.begin(), c.end(), comp); } explicit - priority_queue(const _Compare& __x, - _Sequence&& __s = _Sequence()) + priority_queue(const _Compare& __x, _Sequence&& __s = _Sequence()) : c(std::move(__s)), comp(__x) { std::make_heap(c.begin(), c.end(), comp); } diff --git a/libstdc++-v3/include/bits/stl_stack.h b/libstdc++-v3/include/bits/stl_stack.h index a0f9ee5..094ce65 100644 --- a/libstdc++-v3/include/bits/stl_stack.h +++ b/libstdc++-v3/include/bits/stl_stack.h @@ -129,11 +129,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION protected: // See queue::c for notes on this name. -#if __cplusplus >= 201103L - _Sequence c{}; -#else _Sequence c; -#endif public: // XXX removed old def ctor, added def arg to this one to match 14882 @@ -145,7 +141,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION stack(const _Sequence& __c = _Sequence()) : c(__c) { } #else - stack() = default; + template<typename _Seq = _Sequence, typename _Requires = typename + enable_if<is_default_constructible<_Seq>::value>::type> + stack() + : c() { } explicit stack(const _Sequence& __c) diff --git a/libstdc++-v3/testsuite/23_containers/priority_queue/requirements/constructible.cc b/libstdc++-v3/testsuite/23_containers/priority_queue/requirements/constructible.cc new file mode 100644 index 0000000..fa412f3 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/priority_queue/requirements/constructible.cc @@ -0,0 +1,49 @@ +// { dg-do compile } + +// Copyright (C) 2017 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/>. + + +// This file tests explicit instantiation of library containers. + +#include <queue> + +using std::priority_queue; +using std::vector; + +template<typename A> +constexpr bool default_constructible() +{ return std::is_default_constructible<A>::value; } + +static_assert(default_constructible<priority_queue<int>>(), + "priority_queue<int>"); + +struct NonDefaultConstructible : vector<int> { + NonDefaultConstructible(int) { } +}; +struct Cmp : std::less<int> { + Cmp(int) { } +}; +static_assert( + !default_constructible<priority_queue<int, NonDefaultConstructible>>(), + "priority_queue<int, NonDefaultConstructible>"); +static_assert( + !default_constructible<priority_queue<int, NonDefaultConstructible, Cmp>>(), + "priority_queue<int, NonDefaultConstructible, Cmp>"); +static_assert( + !default_constructible<priority_queue<int, vector<int>, Cmp>>(), + "priority_queue<int, vector<int>, Cmp>"); diff --git a/libstdc++-v3/testsuite/23_containers/priority_queue/requirements/explicit_instantiation/1.cc b/libstdc++-v3/testsuite/23_containers/priority_queue/requirements/explicit_instantiation/1.cc index 77cade0..6386d1d 100644 --- a/libstdc++-v3/testsuite/23_containers/priority_queue/requirements/explicit_instantiation/1.cc +++ b/libstdc++-v3/testsuite/23_containers/priority_queue/requirements/explicit_instantiation/1.cc @@ -31,3 +31,5 @@ struct Cmp : std::less<int> { Cmp(int) { } }; template class std::priority_queue<int, NonDefaultConstructible>; +template class std::priority_queue<int, NonDefaultConstructible, Cmp>; +template class std::priority_queue<int, std::vector<int>, Cmp>; diff --git a/libstdc++-v3/testsuite/23_containers/priority_queue/requirements/explicit_instantiation/1_c++98.cc b/libstdc++-v3/testsuite/23_containers/priority_queue/requirements/explicit_instantiation/1_c++98.cc index 0b5b287..c9530cb 100644 --- a/libstdc++-v3/testsuite/23_containers/priority_queue/requirements/explicit_instantiation/1_c++98.cc +++ b/libstdc++-v3/testsuite/23_containers/priority_queue/requirements/explicit_instantiation/1_c++98.cc @@ -30,4 +30,6 @@ struct NonDefaultConstructible : std::vector<int> { struct Cmp : std::less<int> { Cmp(int) { } }; +template class std::priority_queue<int, NonDefaultConstructible>; template class std::priority_queue<int, NonDefaultConstructible, Cmp>; +template class std::priority_queue<int, std::vector<int>, Cmp>; diff --git a/libstdc++-v3/testsuite/23_containers/queue/requirements/constructible.cc b/libstdc++-v3/testsuite/23_containers/queue/requirements/constructible.cc new file mode 100644 index 0000000..99a8b84 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/queue/requirements/constructible.cc @@ -0,0 +1,37 @@ +// { dg-do compile } + +// Copyright (C) 2017 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/>. + + +// This file tests explicit instantiation of library containers. + +#include <queue> + +using std::queue; + +template<typename A> +constexpr bool default_constructible() +{ return std::is_default_constructible<A>::value; } + +static_assert(default_constructible<queue<int>>(), "queue<int>"); + +struct NonDefaultConstructible : std::deque<int> { + NonDefaultConstructible(int) { } +}; +static_assert(!default_constructible<queue<int, NonDefaultConstructible>>(), + "queue<int, NonDefaultConstructible>"); diff --git a/libstdc++-v3/testsuite/23_containers/stack/requirements/constructible.cc b/libstdc++-v3/testsuite/23_containers/stack/requirements/constructible.cc new file mode 100644 index 0000000..0d6e174 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/stack/requirements/constructible.cc @@ -0,0 +1,37 @@ +// { dg-do compile } + +// Copyright (C) 2017 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/>. + + +// This file tests explicit instantiation of library containers. + +#include <stack> + +using std::stack; + +template<typename A> +constexpr bool default_constructible() +{ return std::is_default_constructible<A>::value; } + +static_assert(default_constructible<stack<int>>(), "stack<int>"); + +struct NonDefaultConstructible : std::deque<int> { + NonDefaultConstructible(int) { } +}; +static_assert(!default_constructible<stack<int, NonDefaultConstructible>>(), + "stack<int, NonDefaultConstructible>"); |