diff --git a/tests/span_tests.cpp b/tests/span_tests.cpp index 620fef3..7a24bc5 100644 --- a/tests/span_tests.cpp +++ b/tests/span_tests.cpp @@ -531,53 +531,6 @@ TEST(span_test, from_convertible_span_constructor) using T = span; EXPECT_DEATH(T{avd}, expected); } - -#ifdef CONFIRM_COMPILATION_ERRORS - { - std::array arr{}; - span avd{arr}; - span avcd = avd; - static_cast(avcd); - } - - { - std::array arr{}; - span avd{arr}; - span avcd = avd; - static_cast(avcd); - } - - { - std::array arr{}; - span avd{arr}; - span avcd = avd; - static_cast(avcd); - } - - { - span avd; - span avb = avd; - static_cast(avb); - } - - { - span s; - span s2 = s; - static_cast(s2); - } - - { - span s; - span s2 = s; - static_cast(s2); - } - - { - span s; - span s2 = s; - static_cast(s2); - } -#endif } TEST(span_test, copy_move_and_assignment) @@ -1023,31 +976,6 @@ TEST(span_test, fixed_size_conversions) static_cast(s); } -#ifdef CONFIRM_COMPILATION_ERRORS - // initialization or assignment to static span that REDUCES size is NOT ok - { - span s = arr; - } - { - span s2 = s4; - static_cast(s2); - } - - // even when done dynamically - { - // this now results in a compile-time error, rather than runtime. - // There is no suitable conversion from dynamic span to fixed span. - span s = arr; - auto f = [&]() { - const span s2 = s; - static_cast(s2); - }; - EXPECT_DEATH(f(), expected); - } -#endif - - // but doing so explicitly is ok - // you can convert statically { const span s2{&arr[0], 2}; @@ -1058,32 +986,9 @@ TEST(span_test, fixed_size_conversions) static_cast(s1); } -#ifdef CONFIRM_COMPILATION_ERRORS - // this is not a legal operation in std::span, so we are no longer supporting it - // conversion from span to span via call to `first` - // then convert from span to span - // The dynamic to fixed extents are not supported in the standard - // to make this work, span would need to be span. - { - - // NB: implicit conversion to span from span - span s1 = s4.first(1); - static_cast(s1); - } -#endif - // initialization or assignment to static span that requires size INCREASE is not ok. int arr2[2] = {1, 2}; -#ifdef CONFIRM_COMPILATION_ERRORS - { - span s3 = arr2; - } - { - span s2 = arr2; - span s4a = s2; - } -#endif { auto f = [&]() { const span _s4{arr2, 2}; @@ -1091,18 +996,6 @@ TEST(span_test, fixed_size_conversions) }; EXPECT_DEATH(f(), expected); } - -#ifdef CONFIRM_COMPILATION_ERRORS - // This no longer compiles. There is no suitable conversion from dynamic span to a fixed size - // span. this should fail - we are trying to assign a small dynamic span to a fixed_size larger - // one - span av = arr2; - auto f = [&]() { - const span _s4 = av; - static_cast(_s4); - }; - EXPECT_DEATH(f(), expected); -#endif } TEST(span_test, interop_with_std_regex) @@ -1273,6 +1166,8 @@ static_assert(!CtorCompilesFor, std::array&>, "!CtorCompilesFor, std::array&>"); static_assert(!CtorCompilesFor, std::array&>, "!CtorCompilesFor, std::array&>"); +static_assert(CtorCompilesFor, const std::string&>, + "CtorCompilesFor, const std::string&>"); static_assert(!CtorCompilesFor, const std::string&>, "!CtorCompilesFor, const std::string&>"); @@ -1308,12 +1203,64 @@ static_assert(CtorCompilesFor, span&>, static_assert(!CtorCompilesFor, span&>, "!CtorCompilesFor, span&>"); +template +static constexpr bool ConversionCompilesFor = false; +template +static constexpr bool + ConversionCompilesFor()(std::declval()))>> = + true; +static_assert(ConversionCompilesFor, span>, + "ConversionCompilesFor, span>"); +static_assert(ConversionCompilesFor, span>, + "ConversionCompilesFor, span>"); +static_assert(!ConversionCompilesFor, std::array>, + "!ConversionCompilesFor, std::array>"); +static_assert(!ConversionCompilesFor, std::array>, + "!ConversionCompilesFor, std::array>"); +static_assert(ConversionCompilesFor, std::vector>, + "ConversionCompilesFor, std::vector>"); +static_assert(!ConversionCompilesFor, std::vector>, + "!ConversionCompilesFor, std::vector>"); +#if __cplusplus < 201703L +static_assert(!ConversionCompilesFor, std::string>, + "!ConversionCompilesFor, std::string>"); +#endif +static_assert(ConversionCompilesFor, const std::string&>, + "ConversionCompilesFor, const std::string&>"); +static_assert(!ConversionCompilesFor, const std::string&>, + "!ConversionCompilesFor, const std::string&>"); +static_assert(!ConversionCompilesFor, span&>, + "!ConversionCompilesFor, span&>"); +static_assert(!ConversionCompilesFor, span&>, + "!ConversionCompilesFor, span&>"); +static_assert(!ConversionCompilesFor, span&>, + "!ConversionCompilesFor, span&>"); +static_assert(!ConversionCompilesFor, span&>, + "!ConversionCompilesFor, span&>"); +static_assert(!ConversionCompilesFor, span&>, + "!ConversionCompilesFor, span&>"); +static_assert(!ConversionCompilesFor, span&>, + "!ConversionCompilesFor, span&>"); +static_assert(!ConversionCompilesFor, span&>, + "!ConversionCompilesFor, span&>"); +static_assert(!ConversionCompilesFor, int[4]>, + "!ConversionCompilesFor, int[4]>"); +static_assert(!ConversionCompilesFor, span>, + "!ConversionCompilesFor, span>"); +static_assert(!ConversionCompilesFor, span>, + "!ConversionCompilesFor, span>"); +static_assert(!ConversionCompilesFor, int[2]>, + "!ConversionCompilesFor, int[2]>"); +static_assert(!ConversionCompilesFor, int[2]>, + "!ConversionCompilesFor, int[2]>"); +static_assert(!ConversionCompilesFor, span>, + "!ConversionCompilesFor, span>"); + template static constexpr bool AsWritableBytesCompilesFor = false; template static constexpr bool AsWritableBytesCompilesFor()))>> = true; -static_assert(AsWritableBytesCompilesFor>, - "AsWriteableBytesCompilesFor>"); +static_assert(AsWritableBytesCompilesFor>, "AsWriteableBytesCompilesFor>"); static_assert(!AsWritableBytesCompilesFor>, "!AsWriteableBytesCompilesFor>");