[libcxx-commits] [libcxx] 37086ea - [libc++] Decouple iterator_traits test from precise Clang diagnostics (#107478)

via libcxx-commits libcxx-commits at lists.llvm.org
Fri Sep 6 09:12:32 PDT 2024


Author: Louis Dionne
Date: 2024-09-06T12:12:29-04:00
New Revision: 37086ea21cd966465694cc6998a6e937846ec28d

URL: https://github.com/llvm/llvm-project/commit/37086ea21cd966465694cc6998a6e937846ec28d
DIFF: https://github.com/llvm/llvm-project/commit/37086ea21cd966465694cc6998a6e937846ec28d.diff

LOG: [libc++] Decouple iterator_traits test from precise Clang diagnostics (#107478)

This makes the test more robust and prevents it from breaking when the
diagnostic changes subtly (e.g. under modules).

Added: 
    libcxx/test/std/iterators/iterator.primitives/iterator.traits/empty.compile.pass.cpp

Modified: 
    

Removed: 
    libcxx/test/std/iterators/iterator.primitives/iterator.traits/empty.verify.cpp


################################################################################
diff  --git a/libcxx/test/std/iterators/iterator.primitives/iterator.traits/empty.compile.pass.cpp b/libcxx/test/std/iterators/iterator.primitives/iterator.traits/empty.compile.pass.cpp
new file mode 100644
index 00000000000000..0ee3e1e7ba8a07
--- /dev/null
+++ b/libcxx/test/std/iterators/iterator.primitives/iterator.traits/empty.compile.pass.cpp
@@ -0,0 +1,132 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// <iterator>
+
+// struct iterator_traits
+// {
+// };
+
+#include <iterator>
+#include <type_traits>
+
+#include "test_macros.h"
+
+template <class...>
+using always_void = void;
+
+#define HAS_XXX(member)                                                                                                \
+  template <class T, class = void>                                                                                     \
+  struct has_##member : std::false_type {};                                                                            \
+  template <class T>                                                                                                   \
+  struct has_##member<T, always_void<typename T::member> > : std::true_type {}
+
+HAS_XXX(
diff erence_type);
+HAS_XXX(value_type);
+HAS_XXX(pointer);
+HAS_XXX(reference);
+HAS_XXX(iterator_category);
+
+struct A {};
+struct NotAnIteratorEmpty {};
+
+struct NotAnIteratorNoDifference {
+  //     typedef int                       
diff erence_type;
+  typedef A value_type;
+  typedef A* pointer;
+  typedef A& reference;
+  typedef std::forward_iterator_tag iterator_category;
+};
+
+struct NotAnIteratorNoValue {
+  typedef int 
diff erence_type;
+  //     typedef A                         value_type;
+  typedef A* pointer;
+  typedef A& reference;
+  typedef std::forward_iterator_tag iterator_category;
+};
+
+struct NotAnIteratorNoPointer {
+  typedef int 
diff erence_type;
+  typedef A value_type;
+  //     typedef A*                        pointer;
+  typedef A& reference;
+  typedef std::forward_iterator_tag iterator_category;
+};
+
+struct NotAnIteratorNoReference {
+  typedef int 
diff erence_type;
+  typedef A value_type;
+  typedef A* pointer;
+  //    typedef A&                        reference;
+  typedef std::forward_iterator_tag iterator_category;
+};
+
+struct NotAnIteratorNoCategory {
+  typedef int 
diff erence_type;
+  typedef A value_type;
+  typedef A* pointer;
+  typedef A& reference;
+  //     typedef std::forward_iterator_tag iterator_category;
+};
+
+void test() {
+  {
+    typedef std::iterator_traits<NotAnIteratorEmpty> T;
+    static_assert(!has_
diff erence_type<T>::value, "");
+    static_assert(!has_value_type<T>::value, "");
+    static_assert(!has_pointer<T>::value, "");
+    static_assert(!has_reference<T>::value, "");
+    static_assert(!has_iterator_category<T>::value, "");
+  }
+
+  {
+    typedef std::iterator_traits<NotAnIteratorNoDifference> T;
+    static_assert(!has_
diff erence_type<T>::value, "");
+    static_assert(!has_value_type<T>::value, "");
+    static_assert(!has_pointer<T>::value, "");
+    static_assert(!has_reference<T>::value, "");
+    static_assert(!has_iterator_category<T>::value, "");
+  }
+
+  {
+    typedef std::iterator_traits<NotAnIteratorNoValue> T;
+    static_assert(!has_
diff erence_type<T>::value, "");
+    static_assert(!has_value_type<T>::value, "");
+    static_assert(!has_pointer<T>::value, "");
+    static_assert(!has_reference<T>::value, "");
+    static_assert(!has_iterator_category<T>::value, "");
+  }
+#if TEST_STD_VER <= 17 || !defined(__cpp_lib_concepts)
+  {
+    typedef std::iterator_traits<NotAnIteratorNoPointer> T;
+    static_assert(!has_
diff erence_type<T>::value, "");
+    static_assert(!has_value_type<T>::value, "");
+    static_assert(!has_pointer<T>::value, "");
+    static_assert(!has_reference<T>::value, "");
+    static_assert(!has_iterator_category<T>::value, "");
+  }
+#endif // TEST_STD_VER <= 17 || !defined(__cpp_lib_concepts)
+  {
+    typedef std::iterator_traits<NotAnIteratorNoReference> T;
+    static_assert(!has_
diff erence_type<T>::value, "");
+    static_assert(!has_value_type<T>::value, "");
+    static_assert(!has_pointer<T>::value, "");
+    static_assert(!has_reference<T>::value, "");
+    static_assert(!has_iterator_category<T>::value, "");
+  }
+
+  {
+    typedef std::iterator_traits<NotAnIteratorNoCategory> T;
+    static_assert(!has_
diff erence_type<T>::value, "");
+    static_assert(!has_value_type<T>::value, "");
+    static_assert(!has_pointer<T>::value, "");
+    static_assert(!has_reference<T>::value, "");
+    static_assert(!has_iterator_category<T>::value, "");
+  }
+}

diff  --git a/libcxx/test/std/iterators/iterator.primitives/iterator.traits/empty.verify.cpp b/libcxx/test/std/iterators/iterator.primitives/iterator.traits/empty.verify.cpp
deleted file mode 100644
index f683ae93beac69..00000000000000
--- a/libcxx/test/std/iterators/iterator.primitives/iterator.traits/empty.verify.cpp
+++ /dev/null
@@ -1,123 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-// <iterator>
-
-// struct iterator_traits
-// {
-// };
-
-#include <iterator>
-#include "test_macros.h"
-
-struct A {};
-struct NotAnIteratorEmpty {};
-
-struct NotAnIteratorNoDifference
-{
-//     typedef int                       
diff erence_type;
-    typedef A                         value_type;
-    typedef A*                        pointer;
-    typedef A&                        reference;
-    typedef std::forward_iterator_tag iterator_category;
-};
-
-struct NotAnIteratorNoValue
-{
-    typedef int                       
diff erence_type;
-//     typedef A                         value_type;
-    typedef A*                        pointer;
-    typedef A&                        reference;
-    typedef std::forward_iterator_tag iterator_category;
-};
-
-struct NotAnIteratorNoPointer
-{
-    typedef int                       
diff erence_type;
-    typedef A                         value_type;
-//     typedef A*                        pointer;
-    typedef A&                        reference;
-    typedef std::forward_iterator_tag iterator_category;
-};
-
-struct NotAnIteratorNoReference
-{
-    typedef int                       
diff erence_type;
-    typedef A                         value_type;
-    typedef A*                        pointer;
-//    typedef A&                        reference;
-    typedef std::forward_iterator_tag iterator_category;
-};
-
-struct NotAnIteratorNoCategory
-{
-    typedef int                       
diff erence_type;
-    typedef A                         value_type;
-    typedef A*                        pointer;
-    typedef A&                        reference;
-//     typedef std::forward_iterator_tag iterator_category;
-};
-
-int main(int, char**)
-{
-    {
-    typedef std::iterator_traits<NotAnIteratorEmpty> T;
-    typedef T::
diff erence_type   DT; // expected-error-re {{no type named '
diff erence_type' in 'std:{{.*}}:iterator_traits<{{.+}}>}}
-    typedef T::value_type        VT; // expected-error-re {{no type named 'value_type' in 'std:{{.*}}:iterator_traits<{{.+}}>}}
-    typedef T::pointer           PT; // expected-error-re {{no type named 'pointer' in 'std:{{.*}}:iterator_traits<{{.+}}>}}
-    typedef T::reference         RT; // expected-error-re {{no type named 'reference' in 'std:{{.*}}:iterator_traits<{{.+}}>}}
-    typedef T::iterator_category CT; // expected-error-re {{no type named 'iterator_category' in 'std:{{.*}}:iterator_traits<{{.+}}>}}
-    }
-
-    {
-    typedef std::iterator_traits<NotAnIteratorNoDifference> T;
-    typedef T::
diff erence_type   DT; // expected-error-re {{no type named '
diff erence_type' in 'std:{{.*}}:iterator_traits<{{.+}}>}}
-    typedef T::value_type        VT; // expected-error-re {{no type named 'value_type' in 'std:{{.*}}:iterator_traits<{{.+}}>}}
-    typedef T::pointer           PT; // expected-error-re {{no type named 'pointer' in 'std:{{.*}}:iterator_traits<{{.+}}>}}
-    typedef T::reference         RT; // expected-error-re {{no type named 'reference' in 'std:{{.*}}:iterator_traits<{{.+}}>}}
-    typedef T::iterator_category CT; // expected-error-re {{no type named 'iterator_category' in 'std:{{.*}}:iterator_traits<{{.+}}>}}
-    }
-
-    {
-    typedef std::iterator_traits<NotAnIteratorNoValue> T;
-    typedef T::
diff erence_type   DT; // expected-error-re {{no type named '
diff erence_type' in 'std:{{.*}}:iterator_traits<{{.+}}>}}
-    typedef T::value_type        VT; // expected-error-re {{no type named 'value_type' in 'std:{{.*}}:iterator_traits<{{.+}}>}}
-    typedef T::pointer           PT; // expected-error-re {{no type named 'pointer' in 'std:{{.*}}:iterator_traits<{{.+}}>}}
-    typedef T::reference         RT; // expected-error-re {{no type named 'reference' in 'std:{{.*}}:iterator_traits<{{.+}}>}}
-    typedef T::iterator_category CT; // expected-error-re {{no type named 'iterator_category' in 'std:{{.*}}:iterator_traits<{{.+}}>}}
-    }
-#if TEST_STD_VER <= 17 || !defined(__cpp_lib_concepts)
-    {
-    typedef std::iterator_traits<NotAnIteratorNoPointer> T;
-    typedef T::
diff erence_type   DT; // expected-error-re {{no type named '
diff erence_type' in 'std:{{.*}}:iterator_traits<{{.+}}>}}
-    typedef T::value_type        VT; // expected-error-re {{no type named 'value_type' in 'std:{{.*}}:iterator_traits<{{.+}}>}}
-    typedef T::pointer           PT; // expected-error-re {{no type named 'pointer' in 'std:{{.*}}:iterator_traits<{{.+}}>}}
-    typedef T::reference         RT; // expected-error-re {{no type named 'reference' in 'std:{{.*}}:iterator_traits<{{.+}}>}}
-    typedef T::iterator_category CT; // expected-error-re {{no type named 'iterator_category' in 'std:{{.*}}:iterator_traits<{{.+}}>}}
-    }
-#endif // TEST_STD_VER <= 17 || !defined(__cpp_lib_concepts)
-    {
-    typedef std::iterator_traits<NotAnIteratorNoReference> T;
-    typedef T::
diff erence_type   DT; // expected-error-re {{no type named '
diff erence_type' in 'std:{{.*}}:iterator_traits<{{.+}}>}}
-    typedef T::value_type        VT; // expected-error-re {{no type named 'value_type' in 'std:{{.*}}:iterator_traits<{{.+}}>}}
-    typedef T::pointer           PT; // expected-error-re {{no type named 'pointer' in 'std:{{.*}}:iterator_traits<{{.+}}>}}
-    typedef T::reference         RT; // expected-error-re {{no type named 'reference' in 'std:{{.*}}:iterator_traits<{{.+}}>}}
-    typedef T::iterator_category CT; // expected-error-re {{no type named 'iterator_category' in 'std:{{.*}}:iterator_traits<{{.+}}>}}
-    }
-
-    {
-    typedef std::iterator_traits<NotAnIteratorNoCategory> T;
-    typedef T::
diff erence_type   DT; // expected-error-re {{no type named '
diff erence_type' in 'std:{{.*}}:iterator_traits<{{.+}}>}}
-    typedef T::value_type        VT; // expected-error-re {{no type named 'value_type' in 'std:{{.*}}:iterator_traits<{{.+}}>}}
-    typedef T::pointer           PT; // expected-error-re {{no type named 'pointer' in 'std:{{.*}}:iterator_traits<{{.+}}>}}
-    typedef T::reference         RT; // expected-error-re {{no type named 'reference' in 'std:{{.*}}:iterator_traits<{{.+}}>}}
-    typedef T::iterator_category CT; // expected-error-re {{no type named 'iterator_category' in 'std:{{.*}}:iterator_traits<{{.+}}>}}
-    }
-
-  return 0;
-}


        


More information about the libcxx-commits mailing list