Skip to content

[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

Merged
merged 1 commit into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 50 additions & 50 deletions libcxx/test/libcxx/utilities/any/allocator.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,62 +39,62 @@ 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;
}

void destroy(Small* p) {
p->~Small();
Small_was_destroyed = true;
}
template <typename... Args>
void construct(Small* p, Args&&... args) {
new (p) Small(std::forward<Args>(args)...);
Small_was_constructed = true;
}

void deallocate(Small*, std::size_t) { assert(false); }
};
} // end namespace std
void destroy(Small* p) {
p->~Small();
Small_was_destroyed = true;
}

void deallocate(Small*, std::size_t) { assert(false); }
};

int main(int, char**) {
// Test large types
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>>);
Expand All @@ -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>>);
Expand Down
Loading
Loading