-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[libc++] Decouple iterator_traits test from precise Clang diagnostics #107478
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ldionne
merged 1 commit into
llvm:main
from
ldionne:review/decouple-iterator-traits-diag
Sep 6, 2024
Merged
[libc++] Decouple iterator_traits test from precise Clang diagnostics #107478
ldionne
merged 1 commit into
llvm:main
from
ldionne:review/decouple-iterator-traits-diag
Sep 6, 2024
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-libcxx Author: Louis Dionne (ldionne) ChangesThis makes the test more robust and prevents it from breaking when the diagnostic changes subtly (e.g. under modules). Full diff: https://github.com/llvm/llvm-project/pull/107478.diff 2 Files Affected:
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..f4220c59bfb1ea
--- /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(difference_type);
+HAS_XXX(value_type);
+HAS_XXX(pointer);
+HAS_XXX(reference);
+HAS_XXX(iterator_category);
+
+struct A {};
+struct NotAnIteratorEmpty {};
+
+struct NotAnIteratorNoDifference {
+ // typedef int difference_type;
+ typedef A value_type;
+ typedef A* pointer;
+ typedef A& reference;
+ typedef std::forward_iterator_tag iterator_category;
+};
+
+struct NotAnIteratorNoValue {
+ typedef int difference_type;
+ // typedef A value_type;
+ typedef A* pointer;
+ typedef A& reference;
+ typedef std::forward_iterator_tag iterator_category;
+};
+
+struct NotAnIteratorNoPointer {
+ typedef int difference_type;
+ typedef A value_type;
+ // typedef A* pointer;
+ typedef A& reference;
+ typedef std::forward_iterator_tag iterator_category;
+};
+
+struct NotAnIteratorNoReference {
+ typedef int difference_type;
+ typedef A value_type;
+ typedef A* pointer;
+ // typedef A& reference;
+ typedef std::forward_iterator_tag iterator_category;
+};
+
+struct NotAnIteratorNoCategory {
+ typedef int difference_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_difference_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_difference_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_difference_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_difference_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_difference_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_difference_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 difference_type;
- typedef A value_type;
- typedef A* pointer;
- typedef A& reference;
- typedef std::forward_iterator_tag iterator_category;
-};
-
-struct NotAnIteratorNoValue
-{
- typedef int difference_type;
-// typedef A value_type;
- typedef A* pointer;
- typedef A& reference;
- typedef std::forward_iterator_tag iterator_category;
-};
-
-struct NotAnIteratorNoPointer
-{
- typedef int difference_type;
- typedef A value_type;
-// typedef A* pointer;
- typedef A& reference;
- typedef std::forward_iterator_tag iterator_category;
-};
-
-struct NotAnIteratorNoReference
-{
- typedef int difference_type;
- typedef A value_type;
- typedef A* pointer;
-// typedef A& reference;
- typedef std::forward_iterator_tag iterator_category;
-};
-
-struct NotAnIteratorNoCategory
-{
- typedef int difference_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::difference_type DT; // expected-error-re {{no type named 'difference_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::difference_type DT; // expected-error-re {{no type named 'difference_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::difference_type DT; // expected-error-re {{no type named 'difference_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::difference_type DT; // expected-error-re {{no type named 'difference_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::difference_type DT; // expected-error-re {{no type named 'difference_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::difference_type DT; // expected-error-re {{no type named 'difference_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;
-}
|
This makes the test more robust and prevents it from breaking when the diagnostic changes subtly (e.g. under modules).
e1fe0c9
to
9b9a764
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This makes the test more robust and prevents it from breaking when the diagnostic changes subtly (e.g. under modules).