From de4b5856bbeed7757780b6c7693d3209dc67845c Mon Sep 17 00:00:00 2001 From: fdumont Date: Thu, 18 Oct 2012 19:50:37 +0000 Subject: [PATCH] =?utf8?q?2012-10-18=20=20Fran=C3=A7ois=20Dumont=20=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit * include/debug/formatter.h (_Debug_msg_id): Add __msg_valid_load_factor. * include/debug/macros.h (__glibcxx_check_max_load_factor): New. * include/debug/unordered_set (unordered_set<>::max_load_factor(float)): Check max load factor is positive. (unordered_multiset<>::max_load_factor(float)): Likewise. * include/debug/unordered_map (unordered_map<>::max_load_factor(float)): Likewise. (unordered_multimap<>::max_load_factor(float)): Likewise. * testsuite/23_containers/unordered_map/debug/max_load_factor_neg.cc: New. * testsuite/23_containers/unordered_multimap/debug/ max_load_factor_neg.cc: New. * testsuite/23_containers/unordered_set/debug/max_load_factor_neg.cc: New. * testsuite/23_containers/unordered_multiset/debug/ max_load_factor_neg.cc: New. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@192575 138bc75d-0d04-0410-961f-82ee72b054a4 --- libstdc++-v3/ChangeLog | 21 +++++++++++++ libstdc++-v3/include/debug/formatter.h | 3 +- libstdc++-v3/include/debug/macros.h | 8 ++++- libstdc++-v3/include/debug/unordered_map | 22 ++++++++++++++ libstdc++-v3/include/debug/unordered_set | 22 ++++++++++++++ libstdc++-v3/src/c++11/debug.cc | 3 +- .../unordered_map/debug/max_load_factor_neg.cc | 34 ++++++++++++++++++++++ .../debug/max_load_factor_neg.cc | 34 ++++++++++++++++++++++ .../debug/max_load_factor_neg.cc | 34 ++++++++++++++++++++++ .../unordered_set/debug/max_load_factor_neg.cc | 34 ++++++++++++++++++++++ 10 files changed, 212 insertions(+), 3 deletions(-) create mode 100644 libstdc++-v3/testsuite/23_containers/unordered_map/debug/max_load_factor_neg.cc create mode 100644 libstdc++-v3/testsuite/23_containers/unordered_multimap/debug/max_load_factor_neg.cc create mode 100644 libstdc++-v3/testsuite/23_containers/unordered_multiset/debug/max_load_factor_neg.cc create mode 100644 libstdc++-v3/testsuite/23_containers/unordered_set/debug/max_load_factor_neg.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 709f47986c0..fabcbc73925 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,24 @@ +2012-10-18 François Dumont + + * include/debug/formatter.h (_Debug_msg_id): Add + __msg_valid_load_factor. + * include/debug/macros.h (__glibcxx_check_max_load_factor): New. + * include/debug/unordered_set + (unordered_set<>::max_load_factor(float)): Check max load factor + is positive. + (unordered_multiset<>::max_load_factor(float)): Likewise. + * include/debug/unordered_map + (unordered_map<>::max_load_factor(float)): Likewise. + (unordered_multimap<>::max_load_factor(float)): Likewise. + * testsuite/23_containers/unordered_map/debug/max_load_factor_neg.cc: + New. + * testsuite/23_containers/unordered_multimap/debug/ + max_load_factor_neg.cc: New. + * testsuite/23_containers/unordered_set/debug/max_load_factor_neg.cc: + New. + * testsuite/23_containers/unordered_multiset/debug/ + max_load_factor_neg.cc: New. + 2012-10-17 Benjamin Kosnik * include/bits/move.h (move_if_noexcept): Mark constexpr. diff --git a/libstdc++-v3/include/debug/formatter.h b/libstdc++-v3/include/debug/formatter.h index 9bed99821e9..1d29d8ce55a 100644 --- a/libstdc++-v3/include/debug/formatter.h +++ b/libstdc++-v3/include/debug/formatter.h @@ -113,7 +113,8 @@ namespace __gnu_debug // self move assign __msg_self_move_assign, // unordered container buckets - __msg_bucket_index_oob + __msg_bucket_index_oob, + __msg_valid_load_factor }; class _Error_formatter diff --git a/libstdc++-v3/include/debug/macros.h b/libstdc++-v3/include/debug/macros.h index a8e2f5facb7..3df0c9bd31d 100644 --- a/libstdc++-v3/include/debug/macros.h +++ b/libstdc++-v3/include/debug/macros.h @@ -324,7 +324,13 @@ _GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_partitioned_upper(_First, _Last, \ // Verify that the container is not self move assigned #define __glibcxx_check_self_move_assign(_Other) \ _GLIBCXX_DEBUG_VERIFY(this != &_Other, \ - _M_message(__gnu_debug::__msg_self_move_assign) \ + _M_message(__gnu_debug::__msg_self_move_assign) \ + ._M_sequence(*this, "this")) + +// Verify that load factor is position +#define __glibcxx_check_max_load_factor(_F) \ +_GLIBCXX_DEBUG_VERIFY(_F > 0.0f, \ + _M_message(__gnu_debug::__msg_valid_load_factor) \ ._M_sequence(*this, "this")) #ifdef _GLIBCXX_DEBUG_PEDANTIC diff --git a/libstdc++-v3/include/debug/unordered_map b/libstdc++-v3/include/debug/unordered_map index e980d8ce4f1..b03772d4cae 100644 --- a/libstdc++-v3/include/debug/unordered_map +++ b/libstdc++-v3/include/debug/unordered_map @@ -230,6 +230,17 @@ namespace __debug return _Base::bucket_size(__b); } + float + max_load_factor() const noexcept + { return _Base::max_load_factor(); } + + void + max_load_factor(float __f) + { + __glibcxx_check_max_load_factor(__f); + _Base::max_load_factor(__f); + } + template std::pair emplace(_Args&&... __args) @@ -670,6 +681,17 @@ namespace __debug return _Base::bucket_size(__b); } + float + max_load_factor() const noexcept + { return _Base::max_load_factor(); } + + void + max_load_factor(float __f) + { + __glibcxx_check_max_load_factor(__f); + _Base::max_load_factor(__f); + } + template iterator emplace(_Args&&... __args) diff --git a/libstdc++-v3/include/debug/unordered_set b/libstdc++-v3/include/debug/unordered_set index 276821d7e83..07d2893b839 100644 --- a/libstdc++-v3/include/debug/unordered_set +++ b/libstdc++-v3/include/debug/unordered_set @@ -230,6 +230,17 @@ namespace __debug return _Base::bucket_size(__b); } + float + max_load_factor() const noexcept + { return _Base::max_load_factor(); } + + void + max_load_factor(float __f) + { + __glibcxx_check_max_load_factor(__f); + _Base::max_load_factor(__f); + } + template std::pair emplace(_Args&&... __args) @@ -665,6 +676,17 @@ namespace __debug return _Base::bucket_size(__b); } + float + max_load_factor() const noexcept + { return _Base::max_load_factor(); } + + void + max_load_factor(float __f) + { + __glibcxx_check_max_load_factor(__f); + _Base::max_load_factor(__f); + } + template iterator emplace(_Args&&... __args) diff --git a/libstdc++-v3/src/c++11/debug.cc b/libstdc++-v3/src/c++11/debug.cc index 6cd93d108e1..8a18026a44e 100644 --- a/libstdc++-v3/src/c++11/debug.cc +++ b/libstdc++-v3/src/c++11/debug.cc @@ -180,7 +180,8 @@ namespace __gnu_debug "function requires a non-empty iterator range [%1.name;, %2.name;)", "attempt to self move assign", "attempt to access container with out-of-bounds bucket index %2;," - " container only holds %3; buckets" + " container only holds %3; buckets", + "load factor shall be positive" }; void diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/debug/max_load_factor_neg.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/debug/max_load_factor_neg.cc new file mode 100644 index 00000000000..57664890672 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_map/debug/max_load_factor_neg.cc @@ -0,0 +1,34 @@ +// Copyright (C) 2012 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 +// . +// +// { dg-require-debug-mode "" } +// { dg-options "-std=c++11" } +// { dg-do run { xfail *-*-* } } + +#include + +void test01() +{ + std::unordered_multimap um; + um.max_load_factor(-1.0f); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multimap/debug/max_load_factor_neg.cc b/libstdc++-v3/testsuite/23_containers/unordered_multimap/debug/max_load_factor_neg.cc new file mode 100644 index 00000000000..b4b15decf77 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multimap/debug/max_load_factor_neg.cc @@ -0,0 +1,34 @@ +// Copyright (C) 2012 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 +// . +// +// { dg-require-debug-mode "" } +// { dg-options "-std=c++11" } +// { dg-do run { xfail *-*-* } } + +#include + +void test01() +{ + std::unordered_map um; + um.max_load_factor(-1.0f); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multiset/debug/max_load_factor_neg.cc b/libstdc++-v3/testsuite/23_containers/unordered_multiset/debug/max_load_factor_neg.cc new file mode 100644 index 00000000000..797eeaafeed --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multiset/debug/max_load_factor_neg.cc @@ -0,0 +1,34 @@ +// Copyright (C) 2012 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 +// . +// +// { dg-require-debug-mode "" } +// { dg-options "-std=c++11" } +// { dg-do run { xfail *-*-* } } + +#include + +void test01() +{ + std::unordered_multiset us; + us.max_load_factor(-1.0f); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/debug/max_load_factor_neg.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/debug/max_load_factor_neg.cc new file mode 100644 index 00000000000..b18e6e592ea --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_set/debug/max_load_factor_neg.cc @@ -0,0 +1,34 @@ +// Copyright (C) 2012 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 +// . +// +// { dg-require-debug-mode "" } +// { dg-options "-std=c++11" } +// { dg-do run { xfail *-*-* } } + +#include + +void test01() +{ + std::unordered_set us; + us.max_load_factor(-1.0f); +} + +int main() +{ + test01(); + return 0; +} -- 2.11.4.GIT