]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
macros.h (__glibcxx_check_non_empty_range): Define.
authorJonathan Wakely <jwakely.gcc@gmail.com>
Sat, 3 Dec 2011 15:35:35 +0000 (15:35 +0000)
committerJonathan Wakely <redi@gcc.gnu.org>
Sat, 3 Dec 2011 15:35:35 +0000 (15:35 +0000)
* include/debug/macros.h (__glibcxx_check_non_empty_range): Define.
* include/debug/debug.h (__glibcxx_requires_non_empty_range): Define.
* include/debug/formatter.h (__msg_non_empty_range): Add.
* src/debug.cc: Message text for __msg_non_empty_range.
* include/bits/stl_heap.h (pop_heap): Check for non-empty range.
* testsuite/25_algorithms/pop_heap/empty_neg.cc: New.

From-SVN: r181970

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/stl_heap.h
libstdc++-v3/include/debug/debug.h
libstdc++-v3/include/debug/formatter.h
libstdc++-v3/include/debug/macros.h
libstdc++-v3/src/debug.cc
libstdc++-v3/testsuite/25_algorithms/pop_heap/empty_neg.cc [new file with mode: 0644]

index 891b1844803886018a55ce6f2469023229aaceb6..c070e89d43293dc0b036c5cd940b05c04f57b741 100644 (file)
@@ -1,3 +1,12 @@
+2011-12-03  Jonathan Wakely  <jwakely.gcc@gmail.com>
+
+       * include/debug/macros.h (__glibcxx_check_non_empty_range): Define.
+       * include/debug/debug.h (__glibcxx_requires_non_empty_range): Define.
+       * include/debug/formatter.h (__msg_non_empty_range): Add.
+       * src/debug.cc: Message text for __msg_non_empty_range.
+       * include/bits/stl_heap.h (pop_heap): Check for non-empty range.
+       * testsuite/25_algorithms/pop_heap/empty_neg.cc: New.
+
 2011-12-03  Jonathan Wakely  <jwakely.gcc@gmail.com>
 
        * doc/xml/manual/utilities.xml: Remove outdated text.
index bd638a351c8381c7cb55efadb1da4ab69845b778..ed7750c2fa746276e6636183dc8f2016cec61744 100644 (file)
@@ -1,7 +1,7 @@
 // Heap implementation -*- C++ -*-
 
-// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
-// Free Software Foundation, Inc.
+// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
+// 2011 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
@@ -270,6 +270,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
    *  @brief  Pop an element off a heap.
    *  @param  __first  Start of heap.
    *  @param  __last   End of heap.
+   *  @pre    [__first, __last) is a valid, non-empty range.
    *  @ingroup heap_algorithms
    *
    *  This operation pops the top of the heap.  The elements __first
@@ -287,6 +288,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
            _RandomAccessIterator>)
       __glibcxx_function_requires(_LessThanComparableConcept<_ValueType>)
+      __glibcxx_requires_non_empty_range(__first, __last);
       __glibcxx_requires_valid_range(__first, __last);
       __glibcxx_requires_heap(__first, __last);
 
index 6ea8e2addba5ea8ccf2f9297bb42691002a8b09f..e07fb127d2b6eb54290a05066dc344db4a340b21 100644 (file)
@@ -1,6 +1,6 @@
 // Debugging support implementation -*- C++ -*-
 
-// Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+// Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
 // Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
@@ -64,6 +64,7 @@ namespace __gnu_debug
 # define _GLIBCXX_DEBUG_ONLY(_Statement) ;
 # define __glibcxx_requires_cond(_Cond,_Msg)
 # define __glibcxx_requires_valid_range(_First,_Last)
+# define __glibcxx_requires_non_empty_range(_First,_Last)
 # define __glibcxx_requires_sorted(_First,_Last)
 # define __glibcxx_requires_sorted_pred(_First,_Last,_Pred)
 # define __glibcxx_requires_sorted_set(_First1,_Last1,_First2)
@@ -96,6 +97,8 @@ namespace __gnu_debug
 # define __glibcxx_requires_cond(_Cond,_Msg) _GLIBCXX_DEBUG_VERIFY(_Cond,_Msg)
 # define __glibcxx_requires_valid_range(_First,_Last) \
      __glibcxx_check_valid_range(_First,_Last)
+# define __glibcxx_requires_non_empty_range(_First,_Last) \
+     __glibcxx_check_non_empty_range(_First,_Last)
 # define __glibcxx_requires_sorted(_First,_Last) \
      __glibcxx_check_sorted(_First,_Last)
 # define __glibcxx_requires_sorted_pred(_First,_Last,_Pred) \
index 8da171972eb3fe2759ebacc9f4d9c84c03d48304..d22a173e3ff560575b5a712a3ee4d51a47247fb7 100644 (file)
@@ -108,7 +108,8 @@ namespace __gnu_debug
     __msg_erase_after_bad,
     __msg_valid_range2,
     // unordered sequence local iterators
-    __msg_local_iter_compare_bad
+    __msg_local_iter_compare_bad,
+    __msg_non_empty_range
   };
 
   class _Error_formatter
index 391839bcad8a0e2454af8037628a6a7c8c2c7296..07d714d353c9d740acb4f6244564e964eb4468d2 100644 (file)
@@ -57,6 +57,13 @@ _GLIBCXX_DEBUG_VERIFY(__gnu_debug::__valid_range(_First, _Last),     \
                      ._M_iterator(_First, #_First)                     \
                      ._M_iterator(_Last, #_Last))
 
+// Verify that [_First, _Last) forms a non-empty iterator range.
+#define __glibcxx_check_non_empty_range(_First,_Last)                  \
+_GLIBCXX_DEBUG_VERIFY(_First != _Last,                                 \
+                     _M_message(__gnu_debug::__msg_non_empty_range)    \
+                     ._M_iterator(_First, #_First)                     \
+                     ._M_iterator(_Last, #_Last))
+
 /** Verify that we can insert into *this with the iterator _Position.
  *  Insertion into a container at a specific position requires that
  *  the iterator be nonsingular, either dereferenceable or past-the-end,
index cb66f70b25f4b545146d73031ba71e1a6375758c..af45ae4f543a6fb6bc7db9183a3230f954e59b59 100644 (file)
@@ -176,7 +176,8 @@ namespace __gnu_debug
     ", \"%2.name;\" shall be before and not equal to \"%3.name;\"",
     // std::unordered_container::local_iterator
     "attempt to compare local iterators from different unordered container"
-    " buckets"
+    " buckets",
+    "function requires a non-empty iterator range [%1.name;, %2.name;)"
   };
 
   void
diff --git a/libstdc++-v3/testsuite/25_algorithms/pop_heap/empty_neg.cc b/libstdc++-v3/testsuite/25_algorithms/pop_heap/empty_neg.cc
new file mode 100644 (file)
index 0000000..57b3f17
--- /dev/null
@@ -0,0 +1,37 @@
+// Copyright (C) 2011 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 Pred 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/>.
+
+// 25.3.6 Heap operations [lib.alg.heap.operations]
+
+// { dg-require-debug-mode "" }
+// { dg-do run { xfail *-*-* } }
+
+#include <algorithm>
+
+void
+test01()
+{
+  int i = 0;
+  std::pop_heap(&i, &i);
+}
+
+int
+main()
+{
+  test01();
+  return 0;
+}