diff options
Diffstat (limited to 'test/std')
15 files changed, 146 insertions, 35 deletions
diff --git a/test/std/containers/sequences/array/array.data/data_const.pass.cpp b/test/std/containers/sequences/array/array.data/data_const.pass.cpp index 58840e940899..5be082eeb843 100644 --- a/test/std/containers/sequences/array/array.data/data_const.pass.cpp +++ b/test/std/containers/sequences/array/array.data/data_const.pass.cpp @@ -14,6 +14,8 @@ #include <array> #include <cassert> +#include "test_macros.h" + // std::array is explicitly allowed to be initialized with A a = { init-list };. // Disable the missing braces warning for this reason. #include "disable_missing_braces_warning.h" @@ -36,4 +38,16 @@ int main() const T* p = c.data(); (void)p; // to placate scan-build } +#if TEST_STD_VER > 14 + { + typedef std::array<int, 5> C; + constexpr C c1{0,1,2,3,4}; + constexpr const C c2{0,1,2,3,4}; + + static_assert ( c1.data() == &c1[0], ""); + static_assert ( *c1.data() == c1[0], ""); + static_assert ( c2.data() == &c2[0], ""); + static_assert ( *c2.data() == c2[0], ""); + } +#endif } diff --git a/test/std/containers/sequences/array/iterators.pass.cpp b/test/std/containers/sequences/array/iterators.pass.cpp index 1f9904e1fa71..7d9050800dea 100644 --- a/test/std/containers/sequences/array/iterators.pass.cpp +++ b/test/std/containers/sequences/array/iterators.pass.cpp @@ -17,6 +17,10 @@ #include "test_macros.h" +// std::array is explicitly allowed to be initialized with A a = { init-list };. +// Disable the missing braces warning for this reason. +#include "disable_missing_braces_warning.h" + int main() { { @@ -109,4 +113,33 @@ int main() } } #endif +#if TEST_STD_VER > 14 + { + typedef std::array<int, 5> C; + constexpr C c{0,1,2,3,4}; + + static_assert ( c.begin() == std::begin(c), ""); + static_assert ( c.cbegin() == std::cbegin(c), ""); + static_assert ( c.end() == std::end(c), ""); + static_assert ( c.cend() == std::cend(c), ""); + + static_assert ( c.rbegin() == std::rbegin(c), ""); + static_assert ( c.crbegin() == std::crbegin(c), ""); + static_assert ( c.rend() == std::rend(c), ""); + static_assert ( c.crend() == std::crend(c), ""); + + static_assert ( std::begin(c) != std::end(c), ""); + static_assert ( std::rbegin(c) != std::rend(c), ""); + static_assert ( std::cbegin(c) != std::cend(c), ""); + static_assert ( std::crbegin(c) != std::crend(c), ""); + + static_assert ( *c.begin() == 0, ""); + static_assert ( *c.rbegin() == 4, ""); + + static_assert ( *std::begin(c) == 0, "" ); + static_assert ( *std::cbegin(c) == 0, "" ); + static_assert ( *std::rbegin(c) == 4, "" ); + static_assert ( *std::crbegin(c) == 4, "" ); + } +#endif } diff --git a/test/std/experimental/utilities/meta/meta.detect/detected_or.pass.cpp b/test/std/experimental/utilities/meta/meta.detect/detected_or.pass.cpp index ffce81459478..dffdb7885096 100644 --- a/test/std/experimental/utilities/meta/meta.detect/detected_or.pass.cpp +++ b/test/std/experimental/utilities/meta/meta.detect/detected_or.pass.cpp @@ -19,7 +19,7 @@ namespace ex = std::experimental; template <typename T> using hasFoo = typename T::Foo; - + struct yesFoo { using Foo = int; }; diff --git a/test/std/experimental/utilities/meta/meta.detect/detected_t.pass.cpp b/test/std/experimental/utilities/meta/meta.detect/detected_t.pass.cpp index 136fb068be3c..333047511b1c 100644 --- a/test/std/experimental/utilities/meta/meta.detect/detected_t.pass.cpp +++ b/test/std/experimental/utilities/meta/meta.detect/detected_t.pass.cpp @@ -19,7 +19,7 @@ namespace ex = std::experimental; template <typename T> using callFoo = decltype(std::declval<T&>().Foo()); - + struct yesFoo { int Foo() { return 0; } }; diff --git a/test/std/experimental/utilities/meta/meta.detect/is_detected.pass.cpp b/test/std/experimental/utilities/meta/meta.detect/is_detected.pass.cpp index d8528a25161e..ab4a54b7f367 100644 --- a/test/std/experimental/utilities/meta/meta.detect/is_detected.pass.cpp +++ b/test/std/experimental/utilities/meta/meta.detect/is_detected.pass.cpp @@ -19,7 +19,7 @@ namespace ex = std::experimental; template <typename T> using copy_assign_t = decltype(std::declval<T&>() = std::declval<T const &>()); - + struct not_assignable { not_assignable & operator=(const not_assignable&) = delete; }; diff --git a/test/std/experimental/utilities/meta/meta.detect/is_detected_convertible.pass.cpp b/test/std/experimental/utilities/meta/meta.detect/is_detected_convertible.pass.cpp index 8d1e0ae825d5..c654a6a076c2 100644 --- a/test/std/experimental/utilities/meta/meta.detect/is_detected_convertible.pass.cpp +++ b/test/std/experimental/utilities/meta/meta.detect/is_detected_convertible.pass.cpp @@ -19,7 +19,7 @@ namespace ex = std::experimental; template <typename T> using callFoo = decltype(std::declval<T&>().Foo()); - + struct yesFoo { int Foo() { return 0; } }; diff --git a/test/std/experimental/utilities/meta/meta.detect/is_detected_exact.pass.cpp b/test/std/experimental/utilities/meta/meta.detect/is_detected_exact.pass.cpp index e9e5d8ce0056..b09763a59f13 100644 --- a/test/std/experimental/utilities/meta/meta.detect/is_detected_exact.pass.cpp +++ b/test/std/experimental/utilities/meta/meta.detect/is_detected_exact.pass.cpp @@ -19,7 +19,7 @@ namespace ex = std::experimental; template <typename T> using callFoo = decltype(std::declval<T&>().Foo()); - + struct yesFoo { int Foo() { return 0; } }; diff --git a/test/std/iterators/iterator.range/begin-end.pass.cpp b/test/std/iterators/iterator.range/begin-end.pass.cpp index 68186919198d..a0774888d567 100644 --- a/test/std/iterators/iterator.range/begin-end.pass.cpp +++ b/test/std/iterators/iterator.range/begin-end.pass.cpp @@ -10,12 +10,25 @@ // XFAIL: c++03, c++98 // <iterator> -// template <class C> auto begin(C& c) -> decltype(c.begin()); -// template <class C> auto begin(const C& c) -> decltype(c.begin()); -// template <class C> auto end(C& c) -> decltype(c.end()); -// template <class C> auto end(const C& c) -> decltype(c.end()); -// template <class E> reverse_iterator<const E*> rbegin(initializer_list<E> il); -// template <class E> reverse_iterator<const E*> rend(initializer_list<E> il); +// template <class C> constexpr auto begin(C& c) -> decltype(c.begin()); +// template <class C> constexpr auto begin(const C& c) -> decltype(c.begin()); +// template <class C> constexpr auto cbegin(const C& c) -> decltype(std::begin(c)); // C++14 +// template <class C> constexpr auto cend(const C& c) -> decltype(std::end(c)); // C++14 +// template <class C> constexpr auto end (C& c) -> decltype(c.end()); +// template <class C> constexpr auto end (const C& c) -> decltype(c.end()); +// template <class E> constexpr reverse_iterator<const E*> rbegin(initializer_list<E> il); +// template <class E> constexpr reverse_iterator<const E*> rend (initializer_list<E> il); +// +// template <class C> auto constexpr rbegin(C& c) -> decltype(c.rbegin()); // C++14 +// template <class C> auto constexpr rbegin(const C& c) -> decltype(c.rbegin()); // C++14 +// template <class C> auto constexpr rend(C& c) -> decltype(c.rend()); // C++14 +// template <class C> constexpr auto rend(const C& c) -> decltype(c.rend()); // C++14 +// template <class T, size_t N> reverse_iterator<T*> constexpr rbegin(T (&array)[N]); // C++14 +// template <class T, size_t N> reverse_iterator<T*> constexpr rend(T (&array)[N]); // C++14 +// template <class C> constexpr auto crbegin(const C& c) -> decltype(std::rbegin(c)); // C++14 +// template <class C> constexpr auto crend(const C& c) -> decltype(std::rend(c)); // C++14 +// +// All of these are constexpr in C++17 #include "test_macros.h" @@ -26,6 +39,10 @@ #include <list> #include <initializer_list> +// std::array is explicitly allowed to be initialized with A a = { init-list };. +// Disable the missing braces warning for this reason. +#include "disable_missing_braces_warning.h" + template<typename C> void test_const_container( const C & c, typename C::value_type val ) { assert ( std::begin(c) == c.begin()); @@ -142,4 +159,43 @@ int main(){ constexpr const int *e = std::cend(arrA); static_assert(e - b == 3, ""); #endif + +#if TEST_STD_VER > 14 + { + typedef std::array<int, 5> C; + constexpr const C c{0,1,2,3,4}; + + static_assert ( c.begin() == std::begin(c), ""); + static_assert ( c.cbegin() == std::cbegin(c), ""); + static_assert ( c.end() == std::end(c), ""); + static_assert ( c.cend() == std::cend(c), ""); + + static_assert ( c.rbegin() == std::rbegin(c), ""); + static_assert ( c.crbegin() == std::crbegin(c), ""); + static_assert ( c.rend() == std::rend(c), ""); + static_assert ( c.crend() == std::crend(c), ""); + + static_assert ( std::begin(c) != std::end(c), ""); + static_assert ( std::rbegin(c) != std::rend(c), ""); + static_assert ( std::cbegin(c) != std::cend(c), ""); + static_assert ( std::crbegin(c) != std::crend(c), ""); + + static_assert ( *c.begin() == 0, ""); + static_assert ( *c.rbegin() == 4, ""); + + static_assert ( *std::begin(c) == 0, "" ); + static_assert ( *std::cbegin(c) == 0, "" ); + static_assert ( *std::rbegin(c) == 4, "" ); + static_assert ( *std::crbegin(c) == 4, "" ); + } + + { + static constexpr const int c[] = {0,1,2,3,4}; + + static_assert ( *std::begin(c) == 0, "" ); + static_assert ( *std::cbegin(c) == 0, "" ); + static_assert ( *std::rbegin(c) == 4, "" ); + static_assert ( *std::crbegin(c) == 4, "" ); + } +#endif } diff --git a/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_const_lvalue_pair.pass.cpp b/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_const_lvalue_pair.pass.cpp index 9effb6eded37..ef3b9302c7a2 100644 --- a/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_const_lvalue_pair.pass.cpp +++ b/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_const_lvalue_pair.pass.cpp @@ -42,6 +42,7 @@ void test_no_inner_alloc() using SA = std::scoped_allocator_adaptor<Alloc>; static_assert(std::uses_allocator<T, CountingAllocator<T> >::value, ""); Pair * ptr = (Pair*)std::malloc(sizeof(Pair)); + assert(ptr != nullptr); Alloc CA(P); SA A(CA); const PairIn in(x, std::move(y)); @@ -68,6 +69,7 @@ void test_no_inner_alloc() using SA = std::scoped_allocator_adaptor<Alloc>; static_assert(std::uses_allocator<T, CountingAllocator<T> >::value, ""); Pair * ptr = (Pair*)std::malloc(sizeof(Pair)); + assert(ptr != nullptr); Alloc CA(P); SA A(CA); const PairIn in(x, y); @@ -104,6 +106,7 @@ void test_with_inner_alloc() static_assert(!std::uses_allocator<T, Outer>::value, ""); static_assert(std::uses_allocator<T, Inner>::value, ""); Pair * ptr = (Pair*)std::malloc(sizeof(Pair)); + assert(ptr != nullptr); Outer O(POuter); Inner I(PInner); SA A(O, I); @@ -134,6 +137,7 @@ void test_with_inner_alloc() static_assert(!std::uses_allocator<T, Outer>::value, ""); static_assert(std::uses_allocator<T, Inner>::value, ""); Pair * ptr = (Pair*)std::malloc(sizeof(Pair)); + assert(ptr != nullptr); Outer O(POuter); Inner I(PInner); SA A(O, I); diff --git a/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_piecewise.pass.cpp b/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_piecewise.pass.cpp index 4d371f206e65..6f31d264280a 100644 --- a/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_piecewise.pass.cpp +++ b/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_piecewise.pass.cpp @@ -42,6 +42,7 @@ void test_no_inner_alloc() using SA = std::scoped_allocator_adaptor<Alloc>; static_assert(std::uses_allocator<T, CountingAllocator<T> >::value, ""); Pair * ptr = (Pair*)std::malloc(sizeof(Pair)); + assert(ptr != nullptr); Alloc CA(P); SA A(CA); A.construct(ptr, std::piecewise_construct, @@ -68,6 +69,7 @@ void test_no_inner_alloc() using SA = std::scoped_allocator_adaptor<Alloc>; static_assert(std::uses_allocator<T, CountingAllocator<T> >::value, ""); Pair * ptr = (Pair*)std::malloc(sizeof(Pair)); + assert(ptr != nullptr); Alloc CA(P); SA A(CA); A.construct(ptr, std::piecewise_construct, @@ -104,6 +106,7 @@ void test_with_inner_alloc() static_assert(!std::uses_allocator<T, Outer>::value, ""); static_assert(std::uses_allocator<T, Inner>::value, ""); Pair * ptr = (Pair*)std::malloc(sizeof(Pair)); + assert(ptr != nullptr); Outer O(POuter); Inner I(PInner); SA A(O, I); @@ -134,6 +137,7 @@ void test_with_inner_alloc() static_assert(!std::uses_allocator<T, Outer>::value, ""); static_assert(std::uses_allocator<T, Inner>::value, ""); Pair * ptr = (Pair*)std::malloc(sizeof(Pair)); + assert(ptr != nullptr); Outer O(POuter); Inner I(PInner); SA A(O, I); diff --git a/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_rvalue.pass.cpp b/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_rvalue.pass.cpp index 1d0fb5157c02..a761b3288060 100644 --- a/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_rvalue.pass.cpp +++ b/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_rvalue.pass.cpp @@ -42,6 +42,7 @@ void test_no_inner_alloc() using SA = std::scoped_allocator_adaptor<Alloc>; static_assert(std::uses_allocator<T, CountingAllocator<T> >::value, ""); Pair * ptr = (Pair*)std::malloc(sizeof(Pair)); + assert(ptr != nullptr); Alloc CA(P); SA A(CA); PairIn in(x, std::move(y)); @@ -68,6 +69,7 @@ void test_no_inner_alloc() using SA = std::scoped_allocator_adaptor<Alloc>; static_assert(std::uses_allocator<T, CountingAllocator<T> >::value, ""); Pair * ptr = (Pair*)std::malloc(sizeof(Pair)); + assert(ptr != nullptr); Alloc CA(P); SA A(CA); PairIn in(x, y); @@ -104,6 +106,7 @@ void test_with_inner_alloc() static_assert(!std::uses_allocator<T, Outer>::value, ""); static_assert(std::uses_allocator<T, Inner>::value, ""); Pair * ptr = (Pair*)std::malloc(sizeof(Pair)); + assert(ptr != nullptr); Outer O(POuter); Inner I(PInner); SA A(O, I); @@ -134,6 +137,7 @@ void test_with_inner_alloc() static_assert(!std::uses_allocator<T, Outer>::value, ""); static_assert(std::uses_allocator<T, Inner>::value, ""); Pair * ptr = (Pair*)std::malloc(sizeof(Pair)); + assert(ptr != nullptr); Outer O(POuter); Inner I(PInner); SA A(O, I); diff --git a/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_values.pass.cpp b/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_values.pass.cpp index 840f4ecc616d..de33eeb2fbda 100644 --- a/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_values.pass.cpp +++ b/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_values.pass.cpp @@ -41,6 +41,7 @@ void test_no_inner_alloc() using SA = std::scoped_allocator_adaptor<Alloc>; static_assert(std::uses_allocator<T, CountingAllocator<T> >::value, ""); Pair * ptr = (Pair*)std::malloc(sizeof(Pair)); + assert(ptr != nullptr); Alloc CA(P); SA A(CA); A.construct(ptr, x, std::move(y)); @@ -65,6 +66,7 @@ void test_no_inner_alloc() using SA = std::scoped_allocator_adaptor<Alloc>; static_assert(std::uses_allocator<T, CountingAllocator<T> >::value, ""); Pair * ptr = (Pair*)std::malloc(sizeof(Pair)); + assert(ptr != nullptr); Alloc CA(P); SA A(CA); A.construct(ptr, std::move(x), y); @@ -99,6 +101,7 @@ void test_with_inner_alloc() static_assert(!std::uses_allocator<T, Outer>::value, ""); static_assert(std::uses_allocator<T, Inner>::value, ""); Pair * ptr = (Pair*)std::malloc(sizeof(Pair)); + assert(ptr != nullptr); Outer O(POuter); Inner I(PInner); SA A(O, I); @@ -127,6 +130,7 @@ void test_with_inner_alloc() static_assert(!std::uses_allocator<T, Outer>::value, ""); static_assert(std::uses_allocator<T, Inner>::value, ""); Pair * ptr = (Pair*)std::malloc(sizeof(Pair)); + assert(ptr != nullptr); Outer O(POuter); Inner I(PInner); SA A(O, I); diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size.fail.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size.fail.cpp index 50c6f17efbef..3f132e47b626 100644 --- a/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size.fail.cpp +++ b/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size.fail.cpp @@ -21,7 +21,7 @@ int main() { - (void)std::tuple_size<std::tuple<> &>::value; // expected-error {{no member named 'value'}} - (void)std::tuple_size<int>::value; // expected-error {{no member named 'value'}} - (void)std::tuple_size<std::tuple<>*>::value; // expected-error {{no member named 'value'}} + (void)std::tuple_size<std::tuple<> &>::value; // expected-error {{implicit instantiation of undefined template}} + (void)std::tuple_size<int>::value; // expected-error {{implicit instantiation of undefined template}} + (void)std::tuple_size<std::tuple<>*>::value; // expected-error {{implicit instantiation of undefined template}} } diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size.pass.cpp index 40214f632e75..3e4145c79cb5 100644 --- a/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size.pass.cpp +++ b/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size.pass.cpp @@ -18,8 +18,6 @@ // UNSUPPORTED: c++98, c++03 #include <tuple> -#include <utility> -#include <array> #include <type_traits> template <class T, class = decltype(std::tuple_size<T>::value)> @@ -27,27 +25,29 @@ constexpr bool has_value(int) { return true; } template <class> constexpr bool has_value(long) { return false; } template <class T> constexpr bool has_value() { return has_value<T>(0); } +struct Dummy {}; template <class T, std::size_t N> void test() { - static_assert(has_value<T>(), ""); static_assert((std::is_base_of<std::integral_constant<std::size_t, N>, std::tuple_size<T> >::value), ""); - static_assert(has_value<const T>(), ""); static_assert((std::is_base_of<std::integral_constant<std::size_t, N>, std::tuple_size<const T> >::value), ""); - static_assert(has_value<volatile T>(), ""); static_assert((std::is_base_of<std::integral_constant<std::size_t, N>, std::tuple_size<volatile T> >::value), ""); - - static_assert(has_value<const volatile T>(), ""); static_assert((std::is_base_of<std::integral_constant<std::size_t, N>, std::tuple_size<const volatile T> >::value), ""); - { - static_assert(!has_value<T &>(), ""); - static_assert(!has_value<T *>(), ""); - } +} + +void test_tuple_size_value_sfinae() { + // Test that the ::value member does not exist + static_assert(has_value<std::tuple<int> const>(), ""); + static_assert(has_value<std::pair<int, long> volatile>(), ""); + static_assert(!has_value<int>(), ""); + static_assert(!has_value<const int>(), ""); + static_assert(!has_value<volatile void>(), ""); + static_assert(!has_value<const volatile std::tuple<int>&>(), ""); } int main() @@ -56,13 +56,5 @@ int main() test<std::tuple<int>, 1>(); test<std::tuple<char, int>, 2>(); test<std::tuple<char, char*, int>, 3>(); - test<std::pair<int, void*>, 2>(); - test<std::array<int, 42>, 42>(); - { - static_assert(!has_value<void>(), ""); - static_assert(!has_value<void*>(), ""); - static_assert(!has_value<int>(), ""); - static_assert(!has_value<std::pair<int, int>*>(), ""); - static_assert(!has_value<std::array<int, 42>&>(), ""); - } + test_tuple_size_value_sfinae(); } diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_v.fail.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_v.fail.cpp index 700dd95c959c..957a683b47f8 100644 --- a/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_v.fail.cpp +++ b/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_v.fail.cpp @@ -22,5 +22,5 @@ int main() (void)std::tuple_size_v<std::tuple<> &>; // expected-note {{requested here}} (void)std::tuple_size_v<int>; // expected-note {{requested here}} (void)std::tuple_size_v<std::tuple<>*>; // expected-note {{requested here}} - // expected-error@tuple:* 3 {{no member named 'value'}} + // expected-error@tuple:* 3 {{implicit instantiation of undefined template}} } |
