Skip to content

Commit 5dfdac7

Browse files
authored
[libc++][NFC] Avoid opening namespace std in the tests (#94160)
This also adds a few FIXMEs where we use UB in the tests.
1 parent 17ba4f4 commit 5dfdac7

File tree

35 files changed

+364
-515
lines changed

35 files changed

+364
-515
lines changed

libcxx/test/libcxx/utilities/any/allocator.pass.cpp

+50-50
Original file line numberDiff line numberDiff line change
@@ -39,62 +39,62 @@ bool Large_was_deallocated = false;
3939
bool Small_was_constructed = false;
4040
bool Small_was_destroyed = false;
4141

42-
namespace std {
43-
template <>
44-
struct allocator<Large> {
45-
using value_type = Large;
46-
using size_type = std::size_t;
47-
using difference_type = std::ptrdiff_t;
48-
using propagate_on_container_move_assignment = std::true_type;
49-
using is_always_equal = std::true_type;
50-
51-
Large* allocate(std::size_t n) {
52-
Large_was_allocated = true;
53-
return static_cast<Large*>(::operator new(n * sizeof(Large)));
54-
}
42+
template <>
43+
struct std::allocator<Large> {
44+
using value_type = Large;
45+
using size_type = std::size_t;
46+
using difference_type = std::ptrdiff_t;
47+
using propagate_on_container_move_assignment = std::true_type;
48+
using is_always_equal = std::true_type;
49+
50+
Large* allocate(std::size_t n) {
51+
Large_was_allocated = true;
52+
return static_cast<Large*>(::operator new(n * sizeof(Large)));
53+
}
5554

56-
template <typename ...Args>
57-
void construct(Large* p, Args&& ...args) {
58-
new (p) Large(std::forward<Args>(args)...);
59-
Large_was_constructed = true;
60-
}
55+
template <typename... Args>
56+
void construct(Large* p, Args&&... args) {
57+
new (p) Large(std::forward<Args>(args)...);
58+
Large_was_constructed = true;
59+
}
6160

62-
void destroy(Large* p) {
63-
p->~Large();
64-
Large_was_destroyed = true;
65-
}
61+
void destroy(Large* p) {
62+
p->~Large();
63+
Large_was_destroyed = true;
64+
}
6665

67-
void deallocate(Large* p, std::size_t) {
68-
Large_was_deallocated = true;
69-
return ::operator delete(p);
70-
}
71-
};
72-
73-
template <>
74-
struct allocator<Small> {
75-
using value_type = Small;
76-
using size_type = std::size_t;
77-
using difference_type = std::ptrdiff_t;
78-
using propagate_on_container_move_assignment = std::true_type;
79-
using is_always_equal = std::true_type;
80-
81-
Small* allocate(std::size_t) { assert(false); return nullptr; }
82-
83-
template <typename ...Args>
84-
void construct(Small* p, Args&& ...args) {
85-
new (p) Small(std::forward<Args>(args)...);
86-
Small_was_constructed = true;
87-
}
66+
void deallocate(Large* p, std::size_t) {
67+
Large_was_deallocated = true;
68+
return ::operator delete(p);
69+
}
70+
};
71+
72+
template <>
73+
struct std::allocator<Small> {
74+
using value_type = Small;
75+
using size_type = std::size_t;
76+
using difference_type = std::ptrdiff_t;
77+
using propagate_on_container_move_assignment = std::true_type;
78+
using is_always_equal = std::true_type;
79+
80+
Small* allocate(std::size_t) {
81+
assert(false);
82+
return nullptr;
83+
}
8884

89-
void destroy(Small* p) {
90-
p->~Small();
91-
Small_was_destroyed = true;
92-
}
85+
template <typename... Args>
86+
void construct(Small* p, Args&&... args) {
87+
new (p) Small(std::forward<Args>(args)...);
88+
Small_was_constructed = true;
89+
}
9390

94-
void deallocate(Small*, std::size_t) { assert(false); }
95-
};
96-
} // end namespace std
91+
void destroy(Small* p) {
92+
p->~Small();
93+
Small_was_destroyed = true;
94+
}
9795

96+
void deallocate(Small*, std::size_t) { assert(false); }
97+
};
9898

9999
int main(int, char**) {
100100
// Test large types

libcxx/test/libcxx/utilities/format/enable_insertable.compile.pass.cpp

+10-14
Original file line numberDiff line numberDiff line change
@@ -62,26 +62,24 @@ struct valid {
6262
void insert(iterator, CharT*, CharT*);
6363
};
6464

65-
namespace std::__format {
6665
template <>
67-
inline constexpr bool __enable_insertable<no_value_type<char>> = true;
66+
inline constexpr bool std::__format::__enable_insertable<no_value_type<char>> = true;
6867
template <>
69-
inline constexpr bool __enable_insertable<no_end<char>> = true;
68+
inline constexpr bool std::__format::__enable_insertable<no_end<char>> = true;
7069
template <>
71-
inline constexpr bool __enable_insertable<no_insert<char>> = true;
70+
inline constexpr bool std::__format::__enable_insertable<no_insert<char>> = true;
7271
template <>
73-
inline constexpr bool __enable_insertable<valid<char>> = true;
72+
inline constexpr bool std::__format::__enable_insertable<valid<char>> = true;
7473
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
7574
template <>
76-
inline constexpr bool __enable_insertable<no_value_type<wchar_t>> = true;
75+
inline constexpr bool std::__format::__enable_insertable<no_value_type<wchar_t>> = true;
7776
template <>
78-
inline constexpr bool __enable_insertable<no_end<wchar_t>> = true;
77+
inline constexpr bool std::__format::__enable_insertable<no_end<wchar_t>> = true;
7978
template <>
80-
inline constexpr bool __enable_insertable<no_insert<wchar_t>> = true;
79+
inline constexpr bool std::__format::__enable_insertable<no_insert<wchar_t>> = true;
8180
template <>
82-
inline constexpr bool __enable_insertable<valid<wchar_t>> = true;
81+
inline constexpr bool std::__format::__enable_insertable<valid<wchar_t>> = true;
8382
#endif
84-
} // namespace std::__format
8583

8684
static_assert(!std::__format::__insertable<no_value_type<char>>);
8785
static_assert(!std::__format::__insertable<no_end<char>>);
@@ -96,12 +94,10 @@ static_assert(!std::__format::__insertable<no_specialization<wchar_t>>);
9694
static_assert(std::__format::__insertable<valid<wchar_t>>);
9795
#endif
9896

99-
namespace std::__format {
10097
template <>
101-
inline constexpr bool __enable_insertable<valid<signed char>> = true;
98+
inline constexpr bool std::__format::__enable_insertable<valid<signed char>> = true;
10299
template <>
103-
inline constexpr bool __enable_insertable<valid<unsigned char>> = true;
104-
} // namespace std::__format
100+
inline constexpr bool std::__format::__enable_insertable<valid<unsigned char>> = true;
105101

106102
static_assert(!std::__format::__insertable<valid<signed char>>);
107103
static_assert(!std::__format::__insertable<valid<unsigned char>>);

0 commit comments

Comments
 (0)