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.
* 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:
/**
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)
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:
/**
: 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); }
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
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)
--- /dev/null
+// { 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>");
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>;
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>;
--- /dev/null
+// { 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>");
--- /dev/null
+// { 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>");