From: Jonathan Wakely Date: Thu, 12 Jan 2017 17:28:36 +0000 (+0000) Subject: PR77528 partially revert r244278 and define default constructors X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=a1f009a65fd70df0962e0d5b94aba313520df357;p=gcc.git 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 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 7a70e250bf7..8bf7d07b9e9 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,19 @@ 2017-01-12 Jonathan Wakely + 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 6417b3067f6..3a52367bf40 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::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, + 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 a0f9ee520dc..094ce65386c 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::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 00000000000..fa412f33771 --- /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 +// . + + +// This file tests explicit instantiation of library containers. + +#include + +using std::priority_queue; +using std::vector; + +template +constexpr bool default_constructible() +{ return std::is_default_constructible::value; } + +static_assert(default_constructible>(), + "priority_queue"); + +struct NonDefaultConstructible : vector { + NonDefaultConstructible(int) { } +}; +struct Cmp : std::less { + Cmp(int) { } +}; +static_assert( + !default_constructible>(), + "priority_queue"); +static_assert( + !default_constructible>(), + "priority_queue"); +static_assert( + !default_constructible, Cmp>>(), + "priority_queue, 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 77cade0c0f6..6386d1d9f66 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 { Cmp(int) { } }; template class std::priority_queue; +template class std::priority_queue; +template class std::priority_queue, 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 0b5b28763d9..c9530cb5cd5 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 { struct Cmp : std::less { Cmp(int) { } }; +template class std::priority_queue; template class std::priority_queue; +template class std::priority_queue, 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 00000000000..99a8b840d96 --- /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 +// . + + +// This file tests explicit instantiation of library containers. + +#include + +using std::queue; + +template +constexpr bool default_constructible() +{ return std::is_default_constructible::value; } + +static_assert(default_constructible>(), "queue"); + +struct NonDefaultConstructible : std::deque { + NonDefaultConstructible(int) { } +}; +static_assert(!default_constructible>(), + "queue"); 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 00000000000..0d6e174a796 --- /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 +// . + + +// This file tests explicit instantiation of library containers. + +#include + +using std::stack; + +template +constexpr bool default_constructible() +{ return std::is_default_constructible::value; } + +static_assert(default_constructible>(), "stack"); + +struct NonDefaultConstructible : std::deque { + NonDefaultConstructible(int) { } +}; +static_assert(!default_constructible>(), + "stack");