aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2016-10-05 13:01:57 +0100
committerJonathan Wakely <redi@gcc.gnu.org>2016-10-05 13:01:57 +0100
commit92805612f4e0cdd33e10282eaf2cc0369bca3293 (patch)
tree29862dbb05dea5afe75206b023fe6e3755a2bd8c
parenta2a64b499a0251618fc156cc70c31a9692d079be (diff)
downloadgcc-92805612f4e0cdd33e10282eaf2cc0369bca3293.zip
gcc-92805612f4e0cdd33e10282eaf2cc0369bca3293.tar.gz
gcc-92805612f4e0cdd33e10282eaf2cc0369bca3293.tar.bz2
PR 70101 fix allocator-extended ctors for std::priority_queue
PR libstdc++/70101 * include/bits/stl_queue.h (priority_queue): Fix allocator-extended constructors. * testsuite/23_containers/priority_queue/allocator.cc: New test. From-SVN: r240781
-rw-r--r--libstdc++-v3/ChangeLog5
-rw-r--r--libstdc++-v3/include/bits/stl_queue.h12
-rw-r--r--libstdc++-v3/testsuite/23_containers/priority_queue/allocator.cc62
3 files changed, 73 insertions, 6 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 57c887d..7035f54 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,5 +1,10 @@
2016-10-05 Jonathan Wakely <jwakely@redhat.com>
+ PR libstdc++/70101
+ * include/bits/stl_queue.h (priority_queue): Fix allocator-extended
+ constructors.
+ * testsuite/23_containers/priority_queue/allocator.cc: New test.
+
PR libstdc++/77864
* include/bits/stl_map.h (map::map()): Use nothrow constructibility
of comparison function in conditional noexcept.
diff --git a/libstdc++-v3/include/bits/stl_queue.h b/libstdc++-v3/include/bits/stl_queue.h
index da984ff..843199c 100644
--- a/libstdc++-v3/include/bits/stl_queue.h
+++ b/libstdc++-v3/include/bits/stl_queue.h
@@ -462,28 +462,28 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _Alloc, typename _Requires = _Uses<_Alloc>>
explicit
priority_queue(const _Alloc& __a)
- : c(__a) { }
+ : c(__a), comp() { }
template<typename _Alloc, typename _Requires = _Uses<_Alloc>>
priority_queue(const _Compare& __x, const _Alloc& __a)
- : c(__x, __a) { }
+ : c(__a), comp(__x) { }
template<typename _Alloc, typename _Requires = _Uses<_Alloc>>
priority_queue(const _Compare& __x, const _Sequence& __c,
const _Alloc& __a)
- : c(__x, __c, __a) { }
+ : c(__c, __a), comp(__x) { }
template<typename _Alloc, typename _Requires = _Uses<_Alloc>>
priority_queue(const _Compare& __x, _Sequence&& __c, const _Alloc& __a)
- : c(__x, std::move(__c), __a) { }
+ : c(std::move(__c), __a), comp(__x) { }
template<typename _Alloc, typename _Requires = _Uses<_Alloc>>
priority_queue(const priority_queue& __q, const _Alloc& __a)
- : c(__q.c, __a) { }
+ : c(__q.c, __a), comp(__q.comp) { }
template<typename _Alloc, typename _Requires = _Uses<_Alloc>>
priority_queue(priority_queue&& __q, const _Alloc& __a)
- : c(std::move(__q.c), __a) { }
+ : c(std::move(__q.c), __a), comp(std::move(__q.comp)) { }
#endif
/**
diff --git a/libstdc++-v3/testsuite/23_containers/priority_queue/allocator.cc b/libstdc++-v3/testsuite/23_containers/priority_queue/allocator.cc
new file mode 100644
index 0000000..dd6ca25
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/priority_queue/allocator.cc
@@ -0,0 +1,62 @@
+// Copyright (C) 2016 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>
+#include <testsuite_hooks.h>
+
+// PR libstdc++/70101
+
+struct comp
+{
+ int init_check[64];
+ bool operator()(int l, int r) const { return l < r; }
+};
+
+struct check_init : std::priority_queue<int, std::vector<int>, comp>
+{
+ template<typename... Args>
+ check_init(Args... args) : priority_queue(args...)
+ {
+ push(0);
+
+ for (int i : comp.init_check)
+ VERIFY( i == 0 ); // Will not fail if *this was value-initialized.
+ }
+};
+
+void
+test01()
+{
+ std::vector<int> vec;
+ comp cmp{};
+ std::allocator<int> alloc;
+ std::priority_queue<int, std::vector<int>, comp> pq;
+ check_init c1( pq, alloc );
+ check_init c2( std::move(pq), alloc );
+ check_init c3( alloc );
+ check_init c4( cmp, alloc );
+ check_init c5( cmp, vec, alloc );
+ check_init c6( cmp, std::move(vec), alloc );
+}
+
+int
+main()
+{
+ test01();
+}