-
Notifications
You must be signed in to change notification settings - Fork 10.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[libc++] Complete overhaul of constexpr support in std::array
This commit adds missing support for constexpr in std::array under all standard modes up to and including C++20. It also transforms the <array> tests to check for constexpr-friendliness under the right standard modes. Fixes https://llvm.org/PR40124 Fixes rdar://57522096 Supersedes https://reviews.llvm.org/D60666 Differential Revision: https://reviews.llvm.org/D80452
- Loading branch information
Showing
38 changed files
with
1,159 additions
and
788 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
libcxx/test/std/containers/sequences/array/aggregate.pass.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// Make sure std::array is an aggregate type. | ||
|
||
#include <array> | ||
#include <type_traits> | ||
|
||
template <typename T> | ||
void tests() | ||
{ | ||
// Test aggregate initialization | ||
{ | ||
std::array<T, 0> a0 = {}; (void)a0; | ||
std::array<T, 1> a1 = {T()}; (void)a1; | ||
std::array<T, 2> a2 = {T(), T()}; (void)a2; | ||
std::array<T, 3> a3 = {T(), T(), T()}; (void)a3; | ||
} | ||
|
||
// Test the is_aggregate trait. | ||
#if TEST_STD_VER >= 17 // The trait is only available in C++17 and above | ||
static_assert(std::is_aggregate<std::array<T, 0> >::value, ""); | ||
static_assert(std::is_aggregate<std::array<T, 1> >::value, ""); | ||
static_assert(std::is_aggregate<std::array<T, 2> >::value, ""); | ||
static_assert(std::is_aggregate<std::array<T, 3> >::value, ""); | ||
static_assert(std::is_aggregate<std::array<T, 4> >::value, ""); | ||
#endif | ||
} | ||
|
||
struct Empty { }; | ||
struct NonEmpty { int i; int j; }; | ||
|
||
int main(int, char**) | ||
{ | ||
tests<char>(); | ||
tests<int>(); | ||
tests<long>(); | ||
tests<float>(); | ||
tests<double>(); | ||
tests<long double>(); | ||
tests<NonEmpty>(); | ||
tests<Empty>(); | ||
|
||
return 0; | ||
} |
Oops, something went wrong.