Commit d2e1d4b7 by Jonathan Wakely Committed by Jonathan Wakely

PR77528 add default constructors for container adaptors

	PR libstdc++/77528
	* include/bits/stl_queue.h (queue::c): Add default member initializer.
	(queue::queue()): Add constructor and define as defaulted.
	(queue::queue(_Sequence&&)): Remove default argument.
	(priority_queue::c, priority_queue::comp): Add default member
	initializers.
	(priority_queue::priority_queue()): Add constructor and define as
	defaulted.
	(priority_queue::priority_queue(const _Compare&, _Sequence&&)):
	Remove default argument for first parameter.
	* include/bits/stl_stack.h (stack::c): Add default member initializer.
	(stack::stack()): Add constructor and define as defaulted.
	(stack::stack(const _Sequence&)): Remove default argument.
	* testsuite/23_containers/priority_queue/requirements/
	explicit_instantiation/1.cc: Test explicit instantiation with
	non-DefaultConstructible sequence.
	* testsuite/23_containers/priority_queue/77528.cc: New test.
	* testsuite/23_containers/priority_queue/requirements/
	explicit_instantiation/1_c++0x.cc: Replace with 1_c++98.cc.
	* testsuite/23_containers/queue/77528.cc: New test.
	* testsuite/23_containers/queue/requirements/explicit_instantiation/
	1.cc: Test explicit instantiation with non-DefaultConstructible
	sequence.
	* testsuite/23_containers/queue/requirements/explicit_instantiation/
	1_c++0x.cc: Replace with 1_c++98.cc.
	* testsuite/23_containers/stack/77528.cc: New test.
	* testsuite/23_containers/stack/requirements/explicit_instantiation/
	1.cc: Test explicit instantiation with non-DefaultConstructible
	sequence.
	* testsuite/23_containers/stack/requirements/explicit_instantiation/
	1_c++0x.cc: Replace with 1_c++98.cc.

From-SVN: r244278
parent 034afd02
2017-01-10 Jonathan Wakely <jwakely@redhat.com>
PR libstdc++/77528
* include/bits/stl_queue.h (queue::c): Add default member initializer.
(queue::queue()): Add constructor and define as defaulted.
(queue::queue(_Sequence&&)): Remove default argument.
(priority_queue::c, priority_queue::comp): Add default member
initializers.
(priority_queue::priority_queue()): Add constructor and define as
defaulted.
(priority_queue::priority_queue(const _Compare&, _Sequence&&)):
Remove default argument for first parameter.
* include/bits/stl_stack.h (stack::c): Add default member initializer.
(stack::stack()): Add constructor and define as defaulted.
(stack::stack(const _Sequence&)): Remove default argument.
* testsuite/23_containers/priority_queue/requirements/
explicit_instantiation/1.cc: Test explicit instantiation with
non-DefaultConstructible sequence.
* testsuite/23_containers/priority_queue/77528.cc: New test.
* testsuite/23_containers/priority_queue/requirements/
explicit_instantiation/1_c++0x.cc: Replace with 1_c++98.cc.
* testsuite/23_containers/queue/77528.cc: New test.
* testsuite/23_containers/queue/requirements/explicit_instantiation/
1.cc: Test explicit instantiation with non-DefaultConstructible
sequence.
* testsuite/23_containers/queue/requirements/explicit_instantiation/
1_c++0x.cc: Replace with 1_c++98.cc.
* testsuite/23_containers/stack/77528.cc: New test.
* testsuite/23_containers/stack/requirements/explicit_instantiation/
1.cc: Test explicit instantiation with non-DefaultConstructible
sequence.
* testsuite/23_containers/stack/requirements/explicit_instantiation/
1_c++0x.cc: Replace with 1_c++98.cc.
2017-01-10 Felipe Magno de Almeida <felipe@expertisesolutions.com.br> 2017-01-10 Felipe Magno de Almeida <felipe@expertisesolutions.com.br>
* include/bits/locale_facets_nonio.tcc * include/bits/locale_facets_nonio.tcc
......
...@@ -124,15 +124,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -124,15 +124,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
typedef _Sequence container_type; typedef _Sequence container_type;
protected: protected:
/** /* Maintainers wondering why this isn't uglified as per style
* 'c' is the underlying container. Maintainers wondering why * guidelines should note that this name is specified in the standard,
* this isn't uglified as per style guidelines should note that * C++98 [23.2.3.1].
* this name is specified in the standard, [23.2.3.1]. (Why? * (Why? Presumably for the same reason that it's protected instead
* Presumably for the same reason that it's protected instead
* of private: to allow derivation. But none of the other * of private: to allow derivation. But none of the other
* containers allow for derivation. Odd.) * containers allow for derivation. Odd.)
*/ */
/// @c c is the underlying container.
#if __cplusplus >= 201103L
_Sequence c{};
#else
_Sequence c; _Sequence c;
#endif
public: public:
/** /**
...@@ -143,12 +147,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -143,12 +147,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
queue(const _Sequence& __c = _Sequence()) queue(const _Sequence& __c = _Sequence())
: c(__c) { } : c(__c) { }
#else #else
queue() = default;
explicit explicit
queue(const _Sequence& __c) queue(const _Sequence& __c)
: c(__c) { } : c(__c) { }
explicit explicit
queue(_Sequence&& __c = _Sequence()) queue(_Sequence&& __c)
: c(std::move(__c)) { } : c(std::move(__c)) { }
template<typename _Alloc, typename _Requires = _Uses<_Alloc>> template<typename _Alloc, typename _Requires = _Uses<_Alloc>>
...@@ -440,8 +446,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -440,8 +446,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
protected: protected:
// See queue::c for notes on these names. // See queue::c for notes on these names.
#if __cplusplus >= 201103L
_Sequence c{};
_Compare comp{};
#else
_Sequence c; _Sequence c;
_Compare comp; _Compare comp;
#endif
public: public:
/** /**
...@@ -454,6 +465,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -454,6 +465,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
: c(__s), comp(__x) : c(__s), comp(__x)
{ std::make_heap(c.begin(), c.end(), comp); } { std::make_heap(c.begin(), c.end(), comp); }
#else #else
priority_queue() = default;
explicit explicit
priority_queue(const _Compare& __x, priority_queue(const _Compare& __x,
const _Sequence& __s) const _Sequence& __s)
...@@ -461,7 +474,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -461,7 +474,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ std::make_heap(c.begin(), c.end(), comp); } { std::make_heap(c.begin(), c.end(), comp); }
explicit explicit
priority_queue(const _Compare& __x = _Compare(), priority_queue(const _Compare& __x,
_Sequence&& __s = _Sequence()) _Sequence&& __s = _Sequence())
: c(std::move(__s)), comp(__x) : c(std::move(__s)), comp(__x)
{ std::make_heap(c.begin(), c.end(), comp); } { std::make_heap(c.begin(), c.end(), comp); }
......
...@@ -129,7 +129,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -129,7 +129,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
protected: protected:
// See queue::c for notes on this name. // See queue::c for notes on this name.
#if __cplusplus >= 201103L
_Sequence c{};
#else
_Sequence c; _Sequence c;
#endif
public: public:
// XXX removed old def ctor, added def arg to this one to match 14882 // XXX removed old def ctor, added def arg to this one to match 14882
...@@ -141,12 +145,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -141,12 +145,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
stack(const _Sequence& __c = _Sequence()) stack(const _Sequence& __c = _Sequence())
: c(__c) { } : c(__c) { }
#else #else
stack() = default;
explicit explicit
stack(const _Sequence& __c) stack(const _Sequence& __c)
: c(__c) { } : c(__c) { }
explicit explicit
stack(_Sequence&& __c = _Sequence()) stack(_Sequence&& __c)
: c(std::move(__c)) { } : c(std::move(__c)) { }
template<typename _Alloc, typename _Requires = _Uses<_Alloc>> template<typename _Alloc, typename _Requires = _Uses<_Alloc>>
......
// 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/>.
// { dg-do run { target c++11 } }
#include <queue>
struct NoCopying : std::vector<int>
{
NoCopying() = default;
NoCopying(const NoCopying& x) : std::vector<int>(x)
{ throw std::bad_alloc(); }
};
void
test01()
{
std::priority_queue<int, NoCopying> q;
}
int
main()
{
test01();
}
...@@ -23,3 +23,11 @@ ...@@ -23,3 +23,11 @@
#include <queue> #include <queue>
template class std::priority_queue<int>; template class std::priority_queue<int>;
struct NonDefaultConstructible : std::vector<int> {
NonDefaultConstructible(int) { }
};
struct Cmp : std::less<int> {
Cmp(int) { }
};
template class std::priority_queue<int, NonDefaultConstructible>;
// { dg-do compile { target c++11 } } // { dg-options "-std=gnu++98" }
// { dg-do compile }
// Copyright (C) 2009-2017 Free Software Foundation, Inc. // Copyright (C) 2009-2017 Free Software Foundation, Inc.
// //
...@@ -22,3 +23,11 @@ ...@@ -22,3 +23,11 @@
#include <queue> #include <queue>
template class std::priority_queue<int>; template class std::priority_queue<int>;
struct NonDefaultConstructible : std::vector<int> {
NonDefaultConstructible(int) { }
};
struct Cmp : std::less<int> {
Cmp(int) { }
};
template class std::priority_queue<int, NonDefaultConstructible, Cmp>;
// 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/>.
// { dg-do run { target c++11 } }
#include <queue>
struct NoCopying : std::deque<int>
{
NoCopying() = default;
NoCopying(const NoCopying& x) : std::deque<int>(x)
{ throw std::bad_alloc(); }
};
void
test01()
{
std::queue<int, NoCopying> q;
}
int
main()
{
test01();
}
...@@ -23,3 +23,8 @@ ...@@ -23,3 +23,8 @@
#include <queue> #include <queue>
template class std::queue<int>; template class std::queue<int>;
struct NonDefaultConstructible : std::deque<int> {
NonDefaultConstructible(int) { }
};
template class std::queue<int, NonDefaultConstructible>;
// { dg-do compile { target c++11 } } // { dg-options "-std=gnu++98" }
// { dg-do compile }
// Copyright (C) 2009-2017 Free Software Foundation, Inc. // Copyright (C) 2009-2017 Free Software Foundation, Inc.
// //
...@@ -22,3 +23,8 @@ ...@@ -22,3 +23,8 @@
#include <queue> #include <queue>
template class std::queue<int>; template class std::queue<int>;
struct NonDefaultConstructible : std::deque<int> {
NonDefaultConstructible(int) { }
};
template class std::queue<int, NonDefaultConstructible>;
// 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/>.
// { dg-do run { target c++11 } }
#include <stack>
struct NoCopying : std::deque<int>
{
NoCopying() = default;
NoCopying(const NoCopying& x) : std::deque<int>(x)
{ throw std::bad_alloc(); }
};
void
test01()
{
std::stack<int, NoCopying> s;
}
int
main()
{
test01();
}
...@@ -23,3 +23,8 @@ ...@@ -23,3 +23,8 @@
#include <stack> #include <stack>
template class std::stack<int>; template class std::stack<int>;
struct NonDefaultConstructible : std::deque<int> {
NonDefaultConstructible(int) { }
};
template class std::stack<int, NonDefaultConstructible>;
// { dg-do compile { target c++11 } } // { dg-options "-std=gnu++98" }
// { dg-do compile }
// Copyright (C) 2009-2017 Free Software Foundation, Inc. // Copyright (C) 2009-2017 Free Software Foundation, Inc.
// //
...@@ -22,3 +23,8 @@ ...@@ -22,3 +23,8 @@
#include <stack> #include <stack>
template class std::stack<int>; template class std::stack<int>;
struct NonDefaultConstructible : std::deque<int> {
NonDefaultConstructible(int) { }
};
template class std::stack<int, NonDefaultConstructible>;
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