-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[libc++][NFC] Avoid opening namespace std in the tests #94160
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
Conversation
✅ With the latest revision this PR passed the C/C++ code formatter. |
This will make it easier for MSVC's STL to consume the |
@llvm/pr-subscribers-libcxx Author: Nikolas Klauser (philnik777) ChangesThis also adds a few FIXMEs where we use UB in the tests. Patch is 66.27 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/94160.diff 35 Files Affected:
diff --git a/libcxx/test/libcxx/utilities/any/allocator.pass.cpp b/libcxx/test/libcxx/utilities/any/allocator.pass.cpp
index daaf74a2783fd..009a4ebed6353 100644
--- a/libcxx/test/libcxx/utilities/any/allocator.pass.cpp
+++ b/libcxx/test/libcxx/utilities/any/allocator.pass.cpp
@@ -39,61 +39,59 @@ bool Large_was_deallocated = false;
bool Small_was_constructed = false;
bool Small_was_destroyed = false;
-namespace std {
- template <>
- struct allocator<Large> {
- using value_type = Large;
- using size_type = std::size_t;
- using difference_type = std::ptrdiff_t;
- using propagate_on_container_move_assignment = std::true_type;
- using is_always_equal = std::true_type;
-
- Large* allocate(std::size_t n) {
- Large_was_allocated = true;
- return static_cast<Large*>(::operator new(n * sizeof(Large)));
- }
+template <>
+struct std::allocator<Large> {
+ using value_type = Large;
+ using size_type = std::size_t;
+ using difference_type = std::ptrdiff_t;
+ using propagate_on_container_move_assignment = std::true_type;
+ using is_always_equal = std::true_type;
+
+ Large* allocate(std::size_t n) {
+ Large_was_allocated = true;
+ return static_cast<Large*>(::operator new(n * sizeof(Large)));
+ }
- template <typename ...Args>
- void construct(Large* p, Args&& ...args) {
- new (p) Large(std::forward<Args>(args)...);
- Large_was_constructed = true;
- }
+ template <typename ...Args>
+ void construct(Large* p, Args&& ...args) {
+ new (p) Large(std::forward<Args>(args)...);
+ Large_was_constructed = true;
+ }
- void destroy(Large* p) {
- p->~Large();
- Large_was_destroyed = true;
- }
+ void destroy(Large* p) {
+ p->~Large();
+ Large_was_destroyed = true;
+ }
- void deallocate(Large* p, std::size_t) {
- Large_was_deallocated = true;
- return ::operator delete(p);
- }
- };
-
- template <>
- struct allocator<Small> {
- using value_type = Small;
- using size_type = std::size_t;
- using difference_type = std::ptrdiff_t;
- using propagate_on_container_move_assignment = std::true_type;
- using is_always_equal = std::true_type;
-
- Small* allocate(std::size_t) { assert(false); return nullptr; }
-
- template <typename ...Args>
- void construct(Small* p, Args&& ...args) {
- new (p) Small(std::forward<Args>(args)...);
- Small_was_constructed = true;
- }
+ void deallocate(Large* p, std::size_t) {
+ Large_was_deallocated = true;
+ return ::operator delete(p);
+ }
+};
+
+template <>
+struct std::allocator<Small> {
+ using value_type = Small;
+ using size_type = std::size_t;
+ using difference_type = std::ptrdiff_t;
+ using propagate_on_container_move_assignment = std::true_type;
+ using is_always_equal = std::true_type;
+
+ Small* allocate(std::size_t) { assert(false); return nullptr; }
+
+ template <typename ...Args>
+ void construct(Small* p, Args&& ...args) {
+ new (p) Small(std::forward<Args>(args)...);
+ Small_was_constructed = true;
+ }
- void destroy(Small* p) {
- p->~Small();
- Small_was_destroyed = true;
- }
+ void destroy(Small* p) {
+ p->~Small();
+ Small_was_destroyed = true;
+ }
- void deallocate(Small*, std::size_t) { assert(false); }
- };
-} // end namespace std
+ void deallocate(Small*, std::size_t) { assert(false); }
+};
int main(int, char**) {
diff --git a/libcxx/test/libcxx/utilities/format/enable_insertable.compile.pass.cpp b/libcxx/test/libcxx/utilities/format/enable_insertable.compile.pass.cpp
index 5c100322fbcf3..9790aeff189e7 100644
--- a/libcxx/test/libcxx/utilities/format/enable_insertable.compile.pass.cpp
+++ b/libcxx/test/libcxx/utilities/format/enable_insertable.compile.pass.cpp
@@ -61,26 +61,24 @@ struct valid {
void insert(iterator, CharT*, CharT*);
};
-namespace std::__format {
template <>
-inline constexpr bool __enable_insertable<no_value_type<char>> = true;
+inline constexpr bool std::__format::__enable_insertable<no_value_type<char>> = true;
template <>
-inline constexpr bool __enable_insertable<no_end<char>> = true;
+inline constexpr bool std::__format::__enable_insertable<no_end<char>> = true;
template <>
-inline constexpr bool __enable_insertable<no_insert<char>> = true;
+inline constexpr bool std::__format::__enable_insertable<no_insert<char>> = true;
template <>
-inline constexpr bool __enable_insertable<valid<char>> = true;
+inline constexpr bool std::__format::__enable_insertable<valid<char>> = true;
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
template <>
-inline constexpr bool __enable_insertable<no_value_type<wchar_t>> = true;
+inline constexpr bool std::__format::__enable_insertable<no_value_type<wchar_t>> = true;
template <>
-inline constexpr bool __enable_insertable<no_end<wchar_t>> = true;
+inline constexpr bool std::__format::__enable_insertable<no_end<wchar_t>> = true;
template <>
-inline constexpr bool __enable_insertable<no_insert<wchar_t>> = true;
+inline constexpr bool std::__format::__enable_insertable<no_insert<wchar_t>> = true;
template <>
-inline constexpr bool __enable_insertable<valid<wchar_t>> = true;
+inline constexpr bool std::__format::__enable_insertable<valid<wchar_t>> = true;
#endif
-} // namespace std::__format
static_assert(!std::__format::__insertable<no_value_type<char>>);
static_assert(!std::__format::__insertable<no_end<char>>);
@@ -95,12 +93,10 @@ static_assert(!std::__format::__insertable<no_specialization<wchar_t>>);
static_assert(std::__format::__insertable<valid<wchar_t>>);
#endif
-namespace std::__format {
template <>
-inline constexpr bool __enable_insertable<valid<signed char>> = true;
+inline constexpr bool std::__format::__enable_insertable<valid<signed char>> = true;
template <>
-inline constexpr bool __enable_insertable<valid<unsigned char>> = true;
-} // namespace std::__format
+inline constexpr bool std::__format::__enable_insertable<valid<unsigned char>> = true;
static_assert(!std::__format::__insertable<valid<signed char>>);
static_assert(!std::__format::__insertable<valid<unsigned char>>);
diff --git a/libcxx/test/std/concepts/concepts.lang/concept.common/common_with.compile.pass.cpp b/libcxx/test/std/concepts/concepts.lang/concept.common/common_with.compile.pass.cpp
index 5d80c1cba2655..91d060e37f098 100644
--- a/libcxx/test/std/concepts/concepts.lang/concept.common/common_with.compile.pass.cpp
+++ b/libcxx/test/std/concepts/concepts.lang/concept.common/common_with.compile.pass.cpp
@@ -262,17 +262,16 @@ struct BadBasicCommonType {
// should be placed so the test doesn't get deleted.
};
-namespace std {
template <>
-struct common_type<BadBasicCommonType, int> {
+struct std::common_type<BadBasicCommonType, int> {
using type = BadBasicCommonType;
};
template <>
-struct common_type<int, BadBasicCommonType> {
+struct std::common_type<int, BadBasicCommonType> {
using type = int;
};
-} // namespace std
+
static_assert(requires {
typename std::common_type_t<BadBasicCommonType, int>;
});
@@ -289,17 +288,16 @@ static_assert(!std::convertible_to<DullCommonType, int>);
struct T1 {};
static_assert(!std::convertible_to<DullCommonType, T1>);
-namespace std {
template <>
-struct common_type<T1, int> {
+struct std::common_type<T1, int> {
using type = DullCommonType;
};
template <>
-struct common_type<int, T1> {
+struct std::common_type<int, T1> {
using type = DullCommonType;
};
-} // namespace std
+
static_assert(HasValidCommonType<T1, int>());
static_assert(!CheckCommonWith<T1, int>());
@@ -314,17 +312,16 @@ struct T2 {};
static_assert(
!std::convertible_to<CommonTypeImplicitlyConstructibleFromInt, T2>);
-namespace std {
template <>
-struct common_type<T2, int> {
+struct std::common_type<T2, int> {
using type = CommonTypeImplicitlyConstructibleFromInt;
};
template <>
-struct common_type<int, T2> {
+struct std::common_type<int, T2> {
using type = CommonTypeImplicitlyConstructibleFromInt;
};
-} // namespace std
+
static_assert(HasValidCommonType<T2, int>());
static_assert(!CheckCommonWith<T2, int>());
@@ -339,17 +336,16 @@ struct T3 {};
static_assert(
!std::convertible_to<CommonTypeExplicitlyConstructibleFromInt, T2>);
-namespace std {
template <>
-struct common_type<T3, int> {
+struct std::common_type<T3, int> {
using type = CommonTypeExplicitlyConstructibleFromInt;
};
template <>
-struct common_type<int, T3> {
+struct std::common_type<int, T3> {
using type = CommonTypeExplicitlyConstructibleFromInt;
};
-} // namespace std
+
static_assert(HasValidCommonType<T3, int>());
static_assert(!CheckCommonWith<T3, int>());
@@ -361,17 +357,16 @@ static_assert(requires(T4 t4) {
static_cast<CommonTypeImplicitlyConstructibleFromT4>(t4);
});
-namespace std {
template <>
-struct common_type<T4, int> {
+struct std::common_type<T4, int> {
using type = CommonTypeImplicitlyConstructibleFromT4;
};
template <>
-struct common_type<int, T4> {
+struct std::common_type<int, T4> {
using type = CommonTypeImplicitlyConstructibleFromT4;
};
-} // namespace std
+
static_assert(HasValidCommonType<T4, int>());
static_assert(!CheckCommonWith<T4, int>());
@@ -383,17 +378,16 @@ static_assert(requires(T5 t5) {
static_cast<CommonTypeExplicitlyConstructibleFromT5>(t5);
});
-namespace std {
template <>
-struct common_type<T5, int> {
+struct std::common_type<T5, int> {
using type = CommonTypeExplicitlyConstructibleFromT5;
};
template <>
-struct common_type<int, T5> {
+struct std::common_type<int, T5> {
using type = CommonTypeExplicitlyConstructibleFromT5;
};
-} // namespace std
+
static_assert(HasValidCommonType<T5, int>());
static_assert(!CheckCommonWith<T5, int>());
@@ -403,113 +397,111 @@ struct CommonTypeNoCommonReference {
CommonTypeNoCommonReference(int);
};
-namespace std {
template <>
-struct common_type<T6, int> {
+struct std::common_type<T6, int> {
using type = CommonTypeNoCommonReference;
};
template <>
-struct common_type<int, T6> {
+struct std::common_type<int, T6> {
using type = CommonTypeNoCommonReference;
};
template <>
-struct common_type<T6&, int&> {};
+struct std::common_type<T6&, int&> {};
template <>
-struct common_type<int&, T6&> {};
+struct std::common_type<int&, T6&> {};
template <>
-struct common_type<T6&, const int&> {};
+struct std::common_type<T6&, const int&> {};
template <>
-struct common_type<int&, const T6&> {};
+struct std::common_type<int&, const T6&> {};
template <>
-struct common_type<T6&, volatile int&> {};
+struct std::common_type<T6&, volatile int&> {};
template <>
-struct common_type<int&, volatile T6&> {};
+struct std::common_type<int&, volatile T6&> {};
template <>
-struct common_type<T6&, const volatile int&> {};
+struct std::common_type<T6&, const volatile int&> {};
template <>
-struct common_type<int&, const volatile T6&> {};
+struct std::common_type<int&, const volatile T6&> {};
template <>
-struct common_type<const T6&, int&> {};
+struct std::common_type<const T6&, int&> {};
template <>
-struct common_type<const int&, T6&> {};
+struct std::common_type<const int&, T6&> {};
template <>
-struct common_type<const T6&, const int&> {};
+struct std::common_type<const T6&, const int&> {};
template <>
-struct common_type<const int&, const T6&> {};
+struct std::common_type<const int&, const T6&> {};
template <>
-struct common_type<const T6&, volatile int&> {};
+struct std::common_type<const T6&, volatile int&> {};
template <>
-struct common_type<const int&, volatile T6&> {};
+struct std::common_type<const int&, volatile T6&> {};
template <>
-struct common_type<const T6&, const volatile int&> {};
+struct std::common_type<const T6&, const volatile int&> {};
template <>
-struct common_type<const int&, const volatile T6&> {};
+struct std::common_type<const int&, const volatile T6&> {};
template <>
-struct common_type<volatile T6&, int&> {};
+struct std::common_type<volatile T6&, int&> {};
template <>
-struct common_type<volatile int&, T6&> {};
+struct std::common_type<volatile int&, T6&> {};
template <>
-struct common_type<volatile T6&, const int&> {};
+struct std::common_type<volatile T6&, const int&> {};
template <>
-struct common_type<volatile int&, const T6&> {};
+struct std::common_type<volatile int&, const T6&> {};
template <>
-struct common_type<volatile T6&, volatile int&> {};
+struct std::common_type<volatile T6&, volatile int&> {};
template <>
-struct common_type<volatile int&, volatile T6&> {};
+struct std::common_type<volatile int&, volatile T6&> {};
template <>
-struct common_type<volatile T6&, const volatile int&> {};
+struct std::common_type<volatile T6&, const volatile int&> {};
template <>
-struct common_type<volatile int&, const volatile T6&> {};
+struct std::common_type<volatile int&, const volatile T6&> {};
template <>
-struct common_type<const volatile T6&, int&> {};
+struct std::common_type<const volatile T6&, int&> {};
template <>
-struct common_type<const volatile int&, T6&> {};
+struct std::common_type<const volatile int&, T6&> {};
template <>
-struct common_type<const volatile T6&, const int&> {};
+struct std::common_type<const volatile T6&, const int&> {};
template <>
-struct common_type<const volatile int&, const T6&> {};
+struct std::common_type<const volatile int&, const T6&> {};
template <>
-struct common_type<const volatile T6&, volatile int&> {};
+struct std::common_type<const volatile T6&, volatile int&> {};
template <>
-struct common_type<const volatile int&, volatile T6&> {};
+struct std::common_type<const volatile int&, volatile T6&> {};
template <>
-struct common_type<const volatile T6&, const volatile int&> {};
+struct std::common_type<const volatile T6&, const volatile int&> {};
template <>
-struct common_type<const volatile int&, const volatile T6&> {};
-} // namespace std
+struct std::common_type<const volatile int&, const volatile T6&> {};
template <typename T, typename U>
constexpr bool HasCommonReference() noexcept {
@@ -526,177 +518,176 @@ struct CommonTypeNoMetaCommonReference {
CommonTypeNoMetaCommonReference(int);
};
-namespace std {
template <>
-struct common_type<T7, int> {
+struct std::common_type<T7, int> {
using type = CommonTypeNoMetaCommonReference;
};
template <>
-struct common_type<int, T7> {
+struct std::common_type<int, T7> {
using type = CommonTypeNoMetaCommonReference;
};
template <>
-struct common_type<T7&, int&> {
+struct std::common_type<T7&, int&> {
using type = void;
};
template <>
-struct common_type<int&, T7&> {
+struct std::common_type<int&, T7&> {
using type = void;
};
template <>
-struct common_type<T7&, const int&> {
+struct std::common_type<T7&, const int&> {
using type = void;
};
template <>
-struct common_type<int&, const T7&> {
+struct std::common_type<int&, const T7&> {
using type = void;
};
template <>
-struct common_type<T7&, volatile int&> {
+struct std::common_type<T7&, volatile int&> {
using type = void;
};
template <>
-struct common_type<int&, volatile T7&> {
+struct std::common_type<int&, volatile T7&> {
using type = void;
};
template <>
-struct common_type<T7&, const volatile int&> {
+struct std::common_type<T7&, const volatile int&> {
using type = void;
};
template <>
-struct common_type<int&, const volatile T7&> {
+struct std::common_type<int&, const volatile T7&> {
using type = void;
};
template <>
-struct common_type<const T7&, int&> {
+struct std::common_type<const T7&, int&> {
using type = void;
};
template <>
-struct common_type<const int&, T7&> {
+struct std::common_type<const int&, T7&> {
using type = void;
};
template <>
-struct common_type<const T7&, const int&> {
+struct std::common_type<const T7&, const int&> {
using type = void;
};
template <>
-struct common_type<const int&, const T7&> {
+struct std::common_type<const int&, const T7&> {
using type = void;
};
template <>
-struct common_type<const T7&, volatile int&> {
+struct std::common_type<const T7&, volatile int&> {
using type = void;
};
template <>
-struct common_type<const int&, volatile T7&> {
+struct std::common_type<const int&, volatile T7&> {
using type = void;
};
template <>
-struct common_type<const T7&, const volatile int&> {
+struct std::common_type<const T7&, const volatile int&> {
using type = void;
};
template <>
-struct common_type<const int&, const volatile T7&> {
+struct std::common_type<const int&, const volatile T7&> {
using type = void;
};
template <>
-struct common_type<volatile T7&, int&> {
+struct std::common_type<volatile T7&, int&> {
using type = void;
};
template <>
-struct common_type<volatile int&, T7&> {
+struct std::common_type<volatile int&, T7&> {
using type = void;
};
template <>
-struct common_type<volatile T7&, const int&> {
+struct std::common_type<volatile T7&, const int&> {
using type = void;
};
template <>
-struct common_type<volatile int&, const T7&> {
+struct std::common_type<volatile int&, const T7&> {
using type = void;
};
template <>
-struct common_type<volatile T7&, volatile int&> {
+struct std::common_type<volatile T7&, volatile int&> {
using type = void;
};
template <>
-struct common_type<volatile int&, volatile T7&> {
+struct std::common_type<volatile int&, volatile T7&> {
using type = void;
};
template <>
-struct common_type<volatile T7&, const volatile int&> {
+struct std::common_type<volatile T7&, const volatile int&> {
using type = void;
};
template <>
-struct common_type<volatile int&, const volatile T7&> {
+struct std::common_type<volatile int&, const volatile T7&> {
using type = void;
};
template <>
-struct common_type<const volatile T7&, int&> {
+struct std::common_type<const volatile T7&, int&> {
using type = void;
};
template <>
-struct common_type<const volatile int&, T7&> {
+struct std::common_type<const volatile int&, T7&> {
using type = void;
};
template <>
-struct common_type<const volatile T7&, const int&> {
+struct std::common_type<const volatile T7&, const int&> {
using type = void;
};
template <>
-struct common_type<const volatile int&, const T7&> {
+struct std::common_type<const volatile int&, const T7&> {
using type = void;
};
template <>
-struct common_type<const volatile T7&, volatile int&> {
+struct std::common_type<const volatile T7&, volatile int&> {
using type = void;
};
template <>
-struct common_type<const volatile int&, volatile T7&> {
+struct std::common_type<const volatile int&, volatile T7&> {
using type = void;
};
template <>
-struct common_type<const volatile T7&, const volatile int&> {
+struct std::common_type<const volatile T7&, const volatile int&> {
using type = void;
};
template <>
-struct common_type<const volatile int&, const volatile T7&> {
+struct std::common_type<const volatile int&, const volatile T7&> {
using type = void;
};
-} // namespace std
+
static_assert(HasValidCommonType<T7, int>());
static_assert(HasValidCommonType<const T7&, const int&>());
static_assert(HasCommonReference<const T7&, const int&>());
@@ -709,284 +700,282 @@ struct CommonWithInt {
operator int() const volatile;
};
-namespace std {
template <>
-struct common_type<CommonWithInt, int> {
+struct std::common_type<CommonWithInt, int> {
using type = int;
};
template <>
-struct common_type<int, CommonWithInt> : common_type<CommonWithInt, int> {};
+struct std::common_type<int, CommonWithInt> : std::common_type<CommonWithInt, int> {};
template <>
-struct common_type<CommonWithInt&, int&> : common_type<CommonWithInt, int> {};
+struct std::common_type<CommonWithInt&, int&> : std::common_type<CommonWithInt, int> {};
template <>
-struct common_type<int&, CommonWithInt&> : common_type<CommonWithInt, int> {};
+struct std::common_type<int&, CommonWithInt&> : std::common_type<CommonWithInt, int> {};
template <>
-struct common_type<CommonWithInt&, const int&>
- : common_type<CommonWithInt, int> {};
+struct std::common_type<CommonWithInt&, const int&>
+ : std::common_type<CommonWithInt, int> {};
template <>
-struct common_type<int&, const CommonWithInt&>
- : common_type<CommonWithInt, int> {};
+struct std::common_type<int&, const CommonWithInt&>
+ : std::common_type<CommonWithInt, int> {};
template <>
-struct common_type<CommonWithInt&, volatile int&>
- : common_type<CommonWithInt, ...
[truncated]
|
9485846
to
8dd7ee6
Compare
8dd7ee6
to
8b24e40
Compare
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/123/builds/2989 Here is the relevant piece of the build log for the reference:
|
This also adds a few FIXMEs where we use UB in the tests.