[libcxx] r177892 - Debug mode: learning to crawl. I need to set up some tests that actually test that the debug mode is working, but that won't cause problems when debug mode isn't on. This is my first prototype of such a test. It should call std::terminate() because it's comparing iterators from different containers. And std::terminate() is rigged up to exit normally. If debug mode fails, and doesn't call terminate, then the program asserts. The test is a no-op if _LIBCPP_DEBUG2 is not defined or is def...

Howard Hinnant hhinnant at apple.com
Mon Mar 25 12:29:36 PDT 2013


Author: hhinnant
Date: Mon Mar 25 14:29:35 2013
New Revision: 177892

URL: http://llvm.org/viewvc/llvm-project?rev=177892&view=rev
Log:
Debug mode: learning to crawl.  I need to set up some tests that actually test that the debug mode is working, but that won't cause problems when debug mode isn't on.  This is my first prototype of such a test.  It should call std::terminate() because it's comparing iterators from different containers.  And std::terminate() is rigged up to exit normally.  If debug mode fails, and doesn't call terminate, then the program asserts.  The test is a no-op if _LIBCPP_DEBUG2 is not defined or is defined to be 0.

Added:
    libcxx/trunk/test/containers/sequences/vector/db_iterators_1.pass.cpp
Modified:
    libcxx/trunk/include/__debug

Modified: libcxx/trunk/include/__debug
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__debug?rev=177892&r1=177891&r2=177892&view=diff
==============================================================================
--- libcxx/trunk/include/__debug (original)
+++ libcxx/trunk/include/__debug Mon Mar 25 14:29:35 2013
@@ -16,7 +16,9 @@
 #   include <cstdlib>
 #   include <cstdio>
 #   include <cstddef>
-#   define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : (_VSTD::printf("%s\n", m), _VSTD::abort()))
+#   ifndef _LIBCPP_ASSERT
+#      define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : (_VSTD::printf("%s\n", m), _VSTD::abort()))
+#   endif
 
 #endif
 

Added: libcxx/trunk/test/containers/sequences/vector/db_iterators_1.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/containers/sequences/vector/db_iterators_1.pass.cpp?rev=177892&view=auto
==============================================================================
--- libcxx/trunk/test/containers/sequences/vector/db_iterators_1.pass.cpp (added)
+++ libcxx/trunk/test/containers/sequences/vector/db_iterators_1.pass.cpp Mon Mar 25 14:29:35 2013
@@ -0,0 +1,53 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <vector>
+
+// iterator       begin();
+// iterator       end();
+// const_iterator begin()  const;
+// const_iterator end()    const;
+// const_iterator cbegin() const;
+// const_iterator cend()   const;
+
+#if _LIBCPP_DEBUG2 >= 1
+
+struct X {};
+
+#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::terminate())
+
+#include <vector>
+#include <cassert>
+#include <iterator>
+#include <exception>
+#include <cstdlib>
+
+void f1()
+{
+    std::exit(0);
+}
+
+int main()
+{
+    std::set_terminate(f1);
+    typedef int T;
+    typedef std::vector<T> C;
+    C c1;
+    C c2;
+    bool b = c1.begin() != c2.begin();
+    assert(false);
+}
+
+#else
+
+int main()
+{
+}
+
+#endif
\ No newline at end of file





More information about the cfe-commits mailing list