diff --git a/include/utility b/include/utility index d476c6b0..a57e17b3 100644 --- a/include/utility +++ b/include/utility @@ -680,6 +680,16 @@ struct _LIBCPP_TYPE_VIS_ONLY integer_sequence template using index_sequence = integer_sequence; +#if __has_builtin(__make_integer_seq) && !defined(_LIBCPP_TESTING_FALLBACK_MAKE_INTEGER_SEQUENCE) + +template +struct __make_integer_sequence +{ + typedef __make_integer_seq type; +}; + +#else + namespace __detail { template struct __repeat; @@ -733,10 +743,12 @@ struct __make_integer_sequence { static_assert(is_integral<_Tp>::value, "std::make_integer_sequence can only be instantiated with an integral type" ); - static_assert(0 <= _Ep, "std::make_integer_sequence input shall not be negative"); + static_assert(0 <= _Ep, "std::make_integer_sequence must have a non-negative sequence length"); typedef __make_integer_sequence_unchecked<_Tp, _Ep> type; }; +#endif + template using make_integer_sequence = typename __make_integer_sequence<_Tp, _Np>::type; diff --git a/test/std/utilities/intseq/intseq.make/make_integer_seq.fail.cpp b/test/std/utilities/intseq/intseq.make/make_integer_seq.fail.cpp index 2dd6c17b..af4a3c4d 100644 --- a/test/std/utilities/intseq/intseq.make/make_integer_seq.fail.cpp +++ b/test/std/utilities/intseq/intseq.make/make_integer_seq.fail.cpp @@ -12,19 +12,23 @@ // template // using make_integer_sequence = integer_sequence; +// UNSUPPORTED: c++98, c++03, c++11 + #include #include #include +#include "test_macros.h" + int main() { -#if _LIBCPP_STD_VER > 11 - - std::make_integer_sequence::value_type i; + typedef std::make_integer_sequence MakeSeqT; + // std::make_integer_sequence is implemented using a compiler builtin if available. + // this builtin has different diagnostic messages than the fallback implementation. +#if TEST_HAS_BUILTIN(__make_integer_seq) && !defined(_LIBCPP_TESTING_FALLBACK_MAKE_INTEGER_SEQUENCE) + MakeSeqT i; // expected-error@utility:* {{integer sequences must have non-negative sequence length}} #else - -X - -#endif // _LIBCPP_STD_VER > 11 + MakeSeqT i; // expected-error@utility:* {{static_assert failed "std::make_integer_sequence must have a non-negative sequence length"}} +#endif } diff --git a/test/std/utilities/intseq/intseq.make/make_integer_seq.pass.cpp b/test/std/utilities/intseq/intseq.make/make_integer_seq.pass.cpp index 7e82b94a..9bfc5f3d 100644 --- a/test/std/utilities/intseq/intseq.make/make_integer_seq.pass.cpp +++ b/test/std/utilities/intseq/intseq.make/make_integer_seq.pass.cpp @@ -12,14 +12,14 @@ // template // using make_integer_sequence = integer_sequence; +// UNSUPPORTED: c++98, c++03, c++11 + #include #include #include int main() { -#if _LIBCPP_STD_VER > 11 - static_assert(std::is_same, std::integer_sequence>::value, ""); static_assert(std::is_same, std::integer_sequence>::value, ""); static_assert(std::is_same, std::integer_sequence>::value, ""); @@ -29,6 +29,4 @@ int main() static_assert(std::is_same, std::integer_sequence>::value, ""); static_assert(std::is_same, std::integer_sequence>::value, ""); static_assert(std::is_same, std::integer_sequence>::value, ""); - -#endif // _LIBCPP_STD_VER > 11 } diff --git a/test/std/utilities/intseq/intseq.make/make_integer_seq_fallback.fail.cpp b/test/std/utilities/intseq/intseq.make/make_integer_seq_fallback.fail.cpp new file mode 100644 index 00000000..b6431b56 --- /dev/null +++ b/test/std/utilities/intseq/intseq.make/make_integer_seq_fallback.fail.cpp @@ -0,0 +1,18 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// using make_integer_sequence = integer_sequence; + +// UNSUPPORTED: c++98, c++03, c++11 + +#define _LIBCPP_TESTING_FALLBACK_MAKE_INTEGER_SEQUENCE +#include "make_integer_seq.fail.cpp" diff --git a/test/std/utilities/intseq/intseq.make/make_integer_seq_fallback.pass.cpp b/test/std/utilities/intseq/intseq.make/make_integer_seq_fallback.pass.cpp new file mode 100644 index 00000000..c75d20b1 --- /dev/null +++ b/test/std/utilities/intseq/intseq.make/make_integer_seq_fallback.pass.cpp @@ -0,0 +1,18 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// using make_integer_sequence = integer_sequence; + +// UNSUPPORTED: c++98, c++03, c++11 + +#define _LIBCPP_TESTING_FALLBACK_MAKE_INTEGER_SEQUENCE +#include "make_integer_seq.pass.cpp" diff --git a/test/support/test_macros.h b/test/support/test_macros.h index 420f4fac..c34e8cf7 100644 --- a/test/support/test_macros.h +++ b/test/support/test_macros.h @@ -26,6 +26,12 @@ #define TEST_HAS_EXTENSION(X) 0 #endif +#ifdef __has_builtin +#define TEST_HAS_BUILTIN(X) __has_builtin(X) +#else +#define TEST_HAS_BUILTIN(X) 0 +#endif + /* Make a nice name for the standard version */ #if __cplusplus <= 199711L # define TEST_STD_VER 3