Replace __cplusplus comparisons and dialect __has_feature checks with TEST_STD_VER.

This is a huge cleanup that helps make the libc++ test suite more portable.
Patch from STL@microsoft.com. Thanks STL!


git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@272716 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Eric Fiselier
2016-06-14 21:31:42 +00:00
parent 174432dbd5
commit d24c465bea
827 changed files with 1085 additions and 988 deletions

View File

@@ -11,7 +11,9 @@
#include <memory>
#include <cassert>
#if __cplusplus >= 201103L
#include "test_macros.h"
#if TEST_STD_VER >= 11
// #include <memory>
//
// template <class Alloc>

View File

@@ -15,6 +15,8 @@
#include <functional>
#include <cassert>
#include "test_macros.h"
struct A
{
char test0() {return 'a';}
@@ -69,7 +71,7 @@ int main()
test0(std::mem_fn(&A::test0));
test1(std::mem_fn(&A::test1));
test2(std::mem_fn(&A::test2));
#if __has_feature(cxx_noexcept)
#if TEST_STD_VER >= 11
static_assert((noexcept(std::mem_fn(&A::test0))), ""); // LWG#2489
#endif
}

View File

@@ -12,7 +12,9 @@
// make sure that we can hash enumeration values
// Not very portable
#if __cplusplus >= 201402L
#include "test_macros.h"
#if TEST_STD_VER >= 14
#include <functional>
#include <cassert>

View File

@@ -21,6 +21,8 @@
#include <type_traits>
#include <cassert>
#include "test_macros.h"
template <class T>
struct A
{
@@ -61,7 +63,7 @@ int main()
const B<int> b = {};
assert(std::allocator_traits<B<int> >::max_size(b) == 100);
}
#if __cplusplus >= 201103
#if TEST_STD_VER >= 11
{
std::allocator<int> a;
static_assert(noexcept(std::allocator_traits<std::allocator<int>>::max_size(a)) == true, "");

View File

@@ -10,7 +10,9 @@
#include <memory>
#include <cassert>
#if __cplusplus >= 201103L
#include "test_macros.h"
#if TEST_STD_VER >= 11
// #include <memory>
//
// template <class Alloc>

View File

@@ -19,6 +19,8 @@
#include <memory>
#include <type_traits>
#include "test_macros.h"
struct A
{
typedef char element_type;

View File

@@ -13,6 +13,8 @@
#include <type_traits>
#include <cassert>
#include "test_macros.h"
int A_constructed = 0;
struct A
@@ -29,7 +31,7 @@ public:
int main()
{
#if __cplusplus >= 201402L
#if TEST_STD_VER >= 14
typedef std::aligned_storage<3*sizeof(A), std::alignment_of<A>::value>::type
Storage;
Storage buffer;

View File

@@ -23,12 +23,15 @@
// atomic_compare_exchange_strong(shared_ptr<T>* p, shared_ptr<T>* v,
// shared_ptr<T> w);
// UNSUPPORTED: c++98, c++03
#include <memory>
#include <cassert>
#include "test_macros.h"
int main()
{
#if __has_feature(cxx_atomic)
{
std::shared_ptr<int> p(new int(4));
std::shared_ptr<int> v(new int(3));
@@ -49,5 +52,4 @@ int main()
assert(*v == 4);
assert(*w == 2);
}
#endif
}

View File

@@ -24,12 +24,15 @@
// shared_ptr<T> w, memory_order success,
// memory_order failure);
// UNSUPPORTED: c++98, c++03
#include <memory>
#include <cassert>
#include "test_macros.h"
int main()
{
#if __has_feature(cxx_atomic)
{
std::shared_ptr<int> p(new int(4));
std::shared_ptr<int> v(new int(3));
@@ -54,5 +57,4 @@ int main()
assert(*v == 4);
assert(*w == 2);
}
#endif
}

View File

@@ -23,12 +23,15 @@
// atomic_compare_exchange_weak(shared_ptr<T>* p, shared_ptr<T>* v,
// shared_ptr<T> w);
// UNSUPPORTED: c++98, c++03
#include <memory>
#include <cassert>
#include "test_macros.h"
int main()
{
#if __has_feature(cxx_atomic)
{
std::shared_ptr<int> p(new int(4));
std::shared_ptr<int> v(new int(3));
@@ -49,5 +52,4 @@ int main()
assert(*v == 4);
assert(*w == 2);
}
#endif
}

View File

@@ -24,12 +24,15 @@
// shared_ptr<T> w, memory_order success,
// memory_order failure);
// UNSUPPORTED: c++98, c++03
#include <memory>
#include <cassert>
#include "test_macros.h"
int main()
{
#if __has_feature(cxx_atomic)
{
std::shared_ptr<int> p(new int(4));
std::shared_ptr<int> v(new int(3));
@@ -54,5 +57,4 @@ int main()
assert(*v == 4);
assert(*w == 2);
}
#endif
}

View File

@@ -22,12 +22,15 @@
// shared_ptr<T>
// atomic_exchange(shared_ptr<T>* p, shared_ptr<T> r)
// UNSUPPORTED: c++98, c++03
#include <memory>
#include <cassert>
#include "test_macros.h"
int main()
{
#if __has_feature(cxx_atomic)
{
std::shared_ptr<int> p(new int(4));
std::shared_ptr<int> r(new int(3));
@@ -35,5 +38,4 @@ int main()
assert(*p == 3);
assert(*r == 4);
}
#endif
}

View File

@@ -22,12 +22,15 @@
// shared_ptr<T>
// atomic_exchange_explicit(shared_ptr<T>* p, shared_ptr<T> r)
// UNSUPPORTED: c++98, c++03
#include <memory>
#include <cassert>
#include "test_macros.h"
int main()
{
#if __has_feature(cxx_atomic)
{
std::shared_ptr<int> p(new int(4));
std::shared_ptr<int> r(new int(3));
@@ -35,5 +38,4 @@ int main()
assert(*p == 3);
assert(*r == 4);
}
#endif
}

View File

@@ -17,15 +17,17 @@
// bool
// atomic_is_lock_free(const shared_ptr<T>* p);
// UNSUPPORTED: c++98, c++03
#include <memory>
#include <cassert>
#include "test_macros.h"
int main()
{
#if __has_feature(cxx_atomic)
{
const std::shared_ptr<int> p(new int(3));
assert(std::atomic_is_lock_free(&p) == false);
}
#endif
}

View File

@@ -22,16 +22,18 @@
// shared_ptr<T>
// atomic_load(const shared_ptr<T>* p)
// UNSUPPORTED: c++98, c++03
#include <memory>
#include <cassert>
#include "test_macros.h"
int main()
{
#if __has_feature(cxx_atomic)
{
std::shared_ptr<int> p(new int(3));
std::shared_ptr<int> q = std::atomic_load(&p);
assert(*q == *p);
}
#endif
}

View File

@@ -22,16 +22,18 @@
// shared_ptr<T>
// atomic_load_explicit(const shared_ptr<T>* p, memory_order mo)
// UNSUPPORTED: c++98, c++03
#include <memory>
#include <cassert>
#include "test_macros.h"
int main()
{
#if __has_feature(cxx_atomic)
{
const std::shared_ptr<int> p(new int(3));
std::shared_ptr<int> q = std::atomic_load_explicit(&p, std::memory_order_relaxed);
assert(*q == *p);
}
#endif
}

View File

@@ -22,17 +22,19 @@
// void
// atomic_store(shared_ptr<T>* p, shared_ptr<T> r)
// UNSUPPORTED: c++98, c++03
#include <memory>
#include <cassert>
#include "test_macros.h"
int main()
{
#if __has_feature(cxx_atomic)
{
std::shared_ptr<int> p;
std::shared_ptr<int> r(new int(3));
std::atomic_store(&p, r);
assert(*p == *r);
}
#endif
}

View File

@@ -22,17 +22,19 @@
// void
// atomic_store_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo)
// UNSUPPORTED: c++98, c++03
#include <memory>
#include <cassert>
#include "test_macros.h"
int main()
{
#if __has_feature(cxx_atomic)
{
std::shared_ptr<int> p;
std::shared_ptr<int> r(new int(3));
std::atomic_store_explicit(&p, r, std::memory_order_seq_cst);
assert(*p == *r);
}
#endif
}

View File

@@ -65,7 +65,7 @@ int main()
assert(test_deleter<A>::count == 0);
assert(test_deleter<A>::dealloc_count == 1);
test_deleter<A>::dealloc_count = 0;
#if __cplusplus >= 201103L
#if TEST_STD_VER >= 11
// Test an allocator that returns class-type pointers
{
std::shared_ptr<A> p(nullptr, test_deleter<A>(1), min_allocator<void>());

View File

@@ -68,7 +68,7 @@ int main()
assert(test_deleter<A>::count == 0);
assert(test_deleter<A>::dealloc_count == 1);
test_deleter<A>::dealloc_count = 0;
#if __cplusplus >= 201103L
#if TEST_STD_VER >= 11
// Test an allocator that returns class-type pointers
{
A* ptr = new A;

View File

@@ -19,6 +19,8 @@
#include <cstdlib>
#include <cassert>
#include "test_macros.h"
bool throw_next = false;
void* operator new(std::size_t s) throw(std::bad_alloc)
@@ -105,7 +107,7 @@ int main()
fn(std::unique_ptr<int>(new int));
}
#if __cplusplus >= 201402L
#if TEST_STD_VER >= 14
// LWG 2415
{
std::unique_ptr<int, void (*)(int*)> p(nullptr, assert_deleter<int>);

View File

@@ -112,7 +112,7 @@ int main()
assert(test_allocator<Two>::alloc_count == 0);
test<bare_allocator<void> >();
#if __cplusplus >= 201103L
#if TEST_STD_VER >= 11
test<min_allocator<void> >();
#endif
}

View File

@@ -14,9 +14,11 @@
#include <type_traits>
#include <cassert>
#include "test_macros.h"
int main()
{
#if __cplusplus > 201402L
#if TEST_STD_VER > 14
typedef std::bool_constant<true> _t;
static_assert(_t::value, "");
static_assert((std::is_same<_t::value_type, bool>::value), "");

View File

@@ -164,7 +164,7 @@ int main()
// Use alignof(std::max_align_t) below to find the max alignment instead of
// hardcoding it, because it's different on different platforms.
// (For example 8 on arm and 16 on x86.)
#if __cplusplus < 201103L
#if TEST_STD_VER < 11
#define alignof __alignof__
#endif
{

View File

@@ -14,6 +14,8 @@
#include <type_traits>
#include <climits>
#include "test_macros.h"
enum E { V = INT_MIN };
enum F { W = UINT_MAX };
@@ -29,7 +31,7 @@ int main()
static_assert((std::is_same<std::underlying_type_t<F>, unsigned>::value), "");
#endif
#if __has_feature(cxx_strong_enums)
#if TEST_STD_VER >= 11
enum G : char { };
static_assert((std::is_same<std::underlying_type<G>::type, char>::value),
@@ -37,5 +39,5 @@ int main()
#if _LIBCPP_STD_VER > 11
static_assert((std::is_same<std::underlying_type_t<G>, char>::value), "");
#endif
#endif // __has_feature(cxx_strong_enums)
#endif // TEST_STD_VER >= 11
}

View File

@@ -13,6 +13,8 @@
#include <type_traits>
#include "test_macros.h"
template <class T>
void test_has_virtual_destructor()
{

View File

@@ -21,7 +21,7 @@ struct A
{
explicit A(int);
A(int, double);
#if __has_feature(cxx_access_control_sfinae)
#if TEST_STD_VER >= 11
private:
#endif
A(char);
@@ -91,7 +91,7 @@ int main()
test_is_constructible<int&, int&> ();
test_is_not_constructible<A> ();
#if __has_feature(cxx_access_control_sfinae)
#if TEST_STD_VER >= 11
test_is_not_constructible<A, char> ();
#else
test_is_constructible<A, char> ();

View File

@@ -79,7 +79,7 @@ int main()
test_is_not_copy_assignable<int[]> ();
test_is_not_copy_assignable<int[3]> ();
#endif
#if __has_feature(cxx_access_control_sfinae)
#if TEST_STD_VER >= 11
test_is_not_copy_assignable<B> ();
#endif
test_is_not_copy_assignable<void> ();

View File

@@ -89,7 +89,7 @@ int main()
test_is_not_copy_constructible<void>();
test_is_not_copy_constructible<Abstract>();
test_is_not_copy_constructible<C>();
#if __has_feature(cxx_access_control_sfinae)
#if TEST_STD_VER >= 11
test_is_not_copy_constructible<B>();
#endif
}

View File

@@ -100,7 +100,7 @@ int main()
test_is_not_default_constructible<char[]>();
test_is_not_default_constructible<Abstract>();
test_is_not_default_constructible<NoDefaultConstructor>();
#if __has_feature(cxx_access_control_sfinae)
#if TEST_STD_VER >= 11
test_is_not_default_constructible<B>();
#endif
}

View File

@@ -65,7 +65,7 @@ class Abstract
virtual ~Abstract() = 0;
};
#if __has_feature(cxx_attributes)
#if TEST_STD_VER >= 11
class Final final {
};
#else

View File

@@ -14,6 +14,8 @@
#include <chrono>
#include <type_traits>
#include "test_macros.h"
template <class T>
void
test()

View File

@@ -9,7 +9,9 @@
// This is for bugs 18853 and 19118
#if __cplusplus >= 201103L
#include "test_macros.h"
#if TEST_STD_VER >= 11
#include <tuple>
#include <functional>

View File

@@ -21,7 +21,9 @@
#include <string>
#include <cassert>
#if __cplusplus > 201103L
#include "test_macros.h"
#if TEST_STD_VER > 11
struct Empty {};

View File

@@ -18,6 +18,8 @@
#include <utility>
#include <cassert>
#include "test_macros.h"
int main()
{
{
@@ -27,7 +29,7 @@ int main()
assert(std::get<1>(p) == 4);
}
#if __cplusplus > 201103L
#if TEST_STD_VER > 11
{
typedef std::pair<int, short> P;
constexpr P p1(3, 4);

View File

@@ -18,7 +18,9 @@
#include <utility>
#include <cassert>
#if __cplusplus > 201103L
#include "test_macros.h"
#if TEST_STD_VER > 11
struct S {
std::pair<int, int> a;
int k;
@@ -41,7 +43,7 @@ int main()
assert(std::get<1>(p) == 6);
}
#if __cplusplus > 201103L
#if TEST_STD_VER > 11
{
static_assert(S().k == 1, "");
static_assert(std::get<1>(getP()) == 4, "");