Ok, 3 major changes for debug mode in one commit:

1.  I had been detecting and trapping iterator == and \!= among iterators
    in different containers as an error.  But the trapping itself is actually
    an error.
    
    Consider:
    
    #include <iostream>
    #include <vector>
    #include <algorithm>

    template <class C>
    void
    display(const C& c)
    {
        std::cout << "{";
        bool first = true;
        for (const auto& x : c)
        {
            if (\!first)
                std::cout << ", ";
            first = false;
            std::cout << x;
        }
        std::cout << "}\n";
    }

    int
    main()
    {
        typedef std::vector<int> V;
        V v1 = {1, 3, 5};
        V v2 = {2, 4, 6};
        display(v1);
        display(v2);
        V::iterator i = std::find(v1.begin(), v1.end(), 1);
        V::iterator j = std::find(v2.begin(), v2.end(), 2);
        if (*i == *j)
            i = j;    // perfectly legal
        // ...
        if (i \!= j)   // the only way to check
            v2.push_back(*i);
        display(v1);
        display(v2);
    }

    It is legal to assign an iterator from one container to another of the
    same type.  This is required to work.  One might want to test whether or
    not such an assignment had been made.  The way one performs such a check
    is using the iterator's ==, \!= operator.  This is a logical and necessary
    function and does not constitute an error.

2.  I had a header circular dependence bug when _LIBCPP_DEBUG2 is defined.
    This caused a problem in several of the libc++ tests.
    Fixed.

3.  There is a serious problem when _LIBCPP_DEBUG2=1 at the moment in that
    std::basic_string is inoperable.  std::basic_string uses __wrap_iterator
    to implement its iterators.  __wrap_iterator has been rigged up in debug
    mode to support vector.  But string hasn't been rigged up yet.  This means
    that one gets false positives when using std::string in debug mode.  I've
    upped std::string's priority in www/debug_mode.html.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@187636 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/__config b/include/__config
index fa6abf6..b1f0d95 100644
--- a/include/__config
+++ b/include/__config
@@ -529,11 +529,4 @@
 #define _LIBCPP_CONSTEXPR_AFTER_CXX11 constexpr
 #endif
 
-
-#ifdef _LIBCPP_DEBUG2
-#   include <__debug>
-#else
-#   define _LIBCPP_ASSERT(x, m) ((void)0)
-#endif
-
 #endif  // _LIBCPP_CONFIG
diff --git a/include/__debug b/include/__debug
index 0d631bf..4c920a7 100644
--- a/include/__debug
+++ b/include/__debug
@@ -171,7 +171,7 @@
     bool __decrementable(const void* __i) const;
     bool __addable(const void* __i, ptrdiff_t __n) const;
     bool __subscriptable(const void* __i, ptrdiff_t __n) const;
-    bool __comparable(const void* __i, const void* __j) const;
+    bool __less_than_comparable(const void* __i, const void* __j) const;
 private:
     _LIBCPP_HIDDEN
     __i_node* __insert_iterator(void* __i);
diff --git a/include/__hash_table b/include/__hash_table
index 0f72294..a8d9222 100644
--- a/include/__hash_table
+++ b/include/__hash_table
@@ -20,6 +20,12 @@
 
 #include <__undef_min_max>
 
+#ifdef _LIBCPP_DEBUG2
+#   include <__debug>
+#else
+#   define _LIBCPP_ASSERT(x, m) ((void)0)
+#endif
+
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
 #endif
@@ -181,10 +187,6 @@
     friend _LIBCPP_INLINE_VISIBILITY
     bool operator==(const __hash_iterator& __x, const __hash_iterator& __y)
     {
-#if _LIBCPP_DEBUG_LEVEL >= 2
-        _LIBCPP_ASSERT(__get_const_db()->__comparable(&__x, &__y),
-                       "Attempted to compare non-comparable unordered container iterator");
-#endif
         return __x.__node_ == __y.__node_;
     }
     friend _LIBCPP_INLINE_VISIBILITY
@@ -329,10 +331,6 @@
     friend _LIBCPP_INLINE_VISIBILITY
     bool operator==(const __hash_const_iterator& __x, const __hash_const_iterator& __y)
     {
-#if _LIBCPP_DEBUG_LEVEL >= 2
-        _LIBCPP_ASSERT(__get_const_db()->__comparable(&__x, &__y),
-                       "Attempted to compare non-comparable unordered container const_iterator");
-#endif
         return __x.__node_ == __y.__node_;
     }
     friend _LIBCPP_INLINE_VISIBILITY
@@ -467,10 +465,6 @@
     friend _LIBCPP_INLINE_VISIBILITY
     bool operator==(const __hash_local_iterator& __x, const __hash_local_iterator& __y)
     {
-#if _LIBCPP_DEBUG_LEVEL >= 2
-        _LIBCPP_ASSERT(__get_const_db()->__comparable(&__x, &__y),
-                       "Attempted to compare non-comparable unordered container local_iterator");
-#endif
         return __x.__node_ == __y.__node_;
     }
     friend _LIBCPP_INLINE_VISIBILITY
@@ -636,10 +630,6 @@
     friend _LIBCPP_INLINE_VISIBILITY
     bool operator==(const __hash_const_local_iterator& __x, const __hash_const_local_iterator& __y)
     {
-#if _LIBCPP_DEBUG_LEVEL >= 2
-        _LIBCPP_ASSERT(__get_const_db()->__comparable(&__x, &__y),
-                       "Attempted to compare non-comparable unordered container local_const_iterator");
-#endif
         return __x.__node_ == __y.__node_;
     }
     friend _LIBCPP_INLINE_VISIBILITY
diff --git a/include/iterator b/include/iterator
index dda053d..4989d8b 100644
--- a/include/iterator
+++ b/include/iterator
@@ -321,8 +321,10 @@
 #include <Availability.h>
 #endif
 
-#ifdef _LIBCPP_DEBUG
-#include <cassert>
+#ifdef _LIBCPP_DEBUG2
+#   include <__debug>
+#else
+#   define _LIBCPP_ASSERT(x, m) ((void)0)
 #endif
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -1264,10 +1266,6 @@
 bool
 operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
 {
-#if _LIBCPP_DEBUG_LEVEL >= 2
-    _LIBCPP_ASSERT(__get_const_db()->__comparable(&__x, &__y),
-                   "Attempted to compare incomparable iterators");
-#endif
     return __x.base() == __y.base();
 }
 
@@ -1277,7 +1275,7 @@
 operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
 {
 #if _LIBCPP_DEBUG_LEVEL >= 2
-    _LIBCPP_ASSERT(__get_const_db()->__comparable(&__x, &__y),
+    _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
                    "Attempted to compare incomparable iterators");
 #endif
     return __x.base() < __y.base();
@@ -1353,7 +1351,7 @@
 operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
 {
 #if _LIBCPP_DEBUG_LEVEL >= 2
-    _LIBCPP_ASSERT(__get_const_db()->__comparable(&__x, &__y),
+    _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
                    "Attempted to subtract incompatible iterators");
 #endif
     return __x.base() - __y.base();
diff --git a/include/list b/include/list
index 628a35b..4041b88 100644
--- a/include/list
+++ b/include/list
@@ -178,6 +178,12 @@
 
 #include <__undef_min_max>
 
+#ifdef _LIBCPP_DEBUG2
+#   include <__debug>
+#else
+#   define _LIBCPP_ASSERT(x, m) ((void)0)
+#endif
+
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
 #endif
@@ -350,10 +356,6 @@
     friend _LIBCPP_INLINE_VISIBILITY
     bool operator==(const __list_iterator& __x, const __list_iterator& __y)
     {
-#if _LIBCPP_DEBUG_LEVEL >= 2
-        _LIBCPP_ASSERT(__get_const_db()->__comparable(&__x, &__y),
-                       "Attempted to compare non-comparable list::iterator");
-#endif
         return __x.__ptr_ == __y.__ptr_;
     }
     friend _LIBCPP_INLINE_VISIBILITY
@@ -491,10 +493,6 @@
     friend _LIBCPP_INLINE_VISIBILITY
     bool operator==(const __list_const_iterator& __x, const __list_const_iterator& __y)
     {
-#if _LIBCPP_DEBUG_LEVEL >= 2
-        _LIBCPP_ASSERT(__get_const_db()->__comparable(&__x, &__y),
-                       "Attempted to compare non-comparable list::const_iterator");
-#endif
         return __x.__ptr_ == __y.__ptr_;
     }
     friend _LIBCPP_INLINE_VISIBILITY
diff --git a/include/vector b/include/vector
index 373e7c1..0758f75 100644
--- a/include/vector
+++ b/include/vector
@@ -272,6 +272,12 @@
 
 #include <__undef_min_max>
 
+#ifdef _LIBCPP_DEBUG2
+#   include <__debug>
+#else
+#   define _LIBCPP_ASSERT(x, m) ((void)0)
+#endif
+
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
 #endif