Use __make_integer_seq builtin for std::make_integer_sequence. Patch by K-ballo.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@255162 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Eric Fiselier
2015-12-09 22:03:06 +00:00
parent 5be047d322
commit 76d2446cf4
6 changed files with 68 additions and 12 deletions

View File

@@ -12,19 +12,23 @@
// template<class T, T N>
// using make_integer_sequence = integer_sequence<T, 0, 1, ..., N-1>;
// UNSUPPORTED: c++98, c++03, c++11
#include <utility>
#include <type_traits>
#include <cassert>
#include "test_macros.h"
int main()
{
#if _LIBCPP_STD_VER > 11
std::make_integer_sequence<int, -3>::value_type i;
typedef std::make_integer_sequence<int, -3> 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
}

View File

@@ -12,14 +12,14 @@
// template<class T, T N>
// using make_integer_sequence = integer_sequence<T, 0, 1, ..., N-1>;
// UNSUPPORTED: c++98, c++03, c++11
#include <utility>
#include <type_traits>
#include <cassert>
int main()
{
#if _LIBCPP_STD_VER > 11
static_assert(std::is_same<std::make_integer_sequence<int, 0>, std::integer_sequence<int>>::value, "");
static_assert(std::is_same<std::make_integer_sequence<int, 1>, std::integer_sequence<int, 0>>::value, "");
static_assert(std::is_same<std::make_integer_sequence<int, 2>, std::integer_sequence<int, 0, 1>>::value, "");
@@ -29,6 +29,4 @@ int main()
static_assert(std::is_same<std::make_integer_sequence<unsigned long long, 1>, std::integer_sequence<unsigned long long, 0>>::value, "");
static_assert(std::is_same<std::make_integer_sequence<unsigned long long, 2>, std::integer_sequence<unsigned long long, 0, 1>>::value, "");
static_assert(std::is_same<std::make_integer_sequence<unsigned long long, 3>, std::integer_sequence<unsigned long long, 0, 1, 2>>::value, "");
#endif // _LIBCPP_STD_VER > 11
}

View File

@@ -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.
//
//===----------------------------------------------------------------------===//
// <utility>
// template<class T, T N>
// using make_integer_sequence = integer_sequence<T, 0, 1, ..., N-1>;
// UNSUPPORTED: c++98, c++03, c++11
#define _LIBCPP_TESTING_FALLBACK_MAKE_INTEGER_SEQUENCE
#include "make_integer_seq.fail.cpp"

View File

@@ -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.
//
//===----------------------------------------------------------------------===//
// <utility>
// template<class T, T N>
// using make_integer_sequence = integer_sequence<T, 0, 1, ..., N-1>;
// UNSUPPORTED: c++98, c++03, c++11
#define _LIBCPP_TESTING_FALLBACK_MAKE_INTEGER_SEQUENCE
#include "make_integer_seq.pass.cpp"