| 1 |
// { dg-do compile { target c++17 } } |
| 2 |
|
| 3 |
// Copyright (C) 2017-2025 Free Software Foundation, Inc. |
| 4 |
// |
| 5 |
// This file is part of the GNU ISO C++ Library. This library is free |
| 6 |
// software; you can redistribute it and/or modify it under the |
| 7 |
// terms of the GNU General Public License as published by the |
| 8 |
// Free Software Foundation; either version 3, or (at your option) |
| 9 |
// any later version. |
| 10 |
// |
| 11 |
// This library is distributed in the hope that it will be useful, |
| 12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
// GNU General Public License for more details. |
| 15 |
// |
| 16 |
// You should have received a copy of the GNU General Public License along |
| 17 |
// with this library; see the file COPYING3. If not see |
| 18 |
// <http://www.gnu.org/licenses/>. |
| 19 |
|
| 20 |
#include <type_traits> |
| 21 |
#include <testsuite_tr1.h> |
| 22 |
#include <tuple> |
| 23 |
|
| 24 |
template <class... T> void pos() |
| 25 |
{ |
| 26 |
static_assert((std::is_aggregate_v<T> &&...)); |
| 27 |
} |
| 28 |
|
| 29 |
template <class... T> void neg() |
| 30 |
{ |
| 31 |
static_assert((!std::is_aggregate_v<T> &&...)); |
| 32 |
} |
| 33 |
|
| 34 |
void test01() |
| 35 |
{ |
| 36 |
using namespace __gnu_test; |
| 37 |
using __gnu_test::test_category; |
| 38 |
using std::is_aggregate; |
| 39 |
|
| 40 |
// Positive tests. |
| 41 |
static_assert(test_category<is_aggregate, |
| 42 |
ClassType>(true), ""); |
| 43 |
static_assert(test_category<is_aggregate, |
| 44 |
UnionType>(true), ""); |
| 45 |
static_assert(test_category<is_aggregate, |
| 46 |
SLType>(true), ""); |
| 47 |
static_assert(test_category<is_aggregate, |
| 48 |
unsigned[3]>(true), ""); |
| 49 |
static_assert(test_category<is_aggregate, |
| 50 |
unsigned[3][2]>(true), ""); |
| 51 |
static_assert(test_category<is_aggregate, |
| 52 |
unsigned[]>(true), ""); |
| 53 |
static_assert(test_category<is_aggregate, |
| 54 |
unsigned[][2]>(true), ""); |
| 55 |
static_assert(test_category<is_aggregate, |
| 56 |
EnumType[3]>(true), ""); |
| 57 |
static_assert(test_category<is_aggregate, |
| 58 |
EnumType[3][2]>(true), ""); |
| 59 |
static_assert(test_category<is_aggregate, |
| 60 |
EnumType[]>(true), ""); |
| 61 |
static_assert(test_category<is_aggregate, |
| 62 |
EnumType[][2]>(true), ""); |
| 63 |
pos<ClassType, UnionType, SLType, |
| 64 |
unsigned[3], unsigned[3][2], unsigned[], unsigned[][3]>(); |
| 65 |
#if __cplusplus == 201703L |
| 66 |
static_assert(test_category<is_aggregate, |
| 67 |
NoexceptMoveAssignClass>(true), ""); |
| 68 |
pos<NoexceptMoveAssignClass>(); |
| 69 |
#endif |
| 70 |
|
| 71 |
// Negative tests. |
| 72 |
static_assert(test_category<is_aggregate, |
| 73 |
AbstractClass>(false), ""); |
| 74 |
static_assert(test_category<is_aggregate, |
| 75 |
PolymorphicClass>(false), ""); |
| 76 |
static_assert(test_category<is_aggregate, |
| 77 |
ExplicitClass>(false), ""); |
| 78 |
static_assert(test_category<is_aggregate, |
| 79 |
char>(false), ""); |
| 80 |
static_assert(test_category<is_aggregate, |
| 81 |
unsigned char>(false), ""); |
| 82 |
static_assert(test_category<is_aggregate, |
| 83 |
signed char>(false), ""); |
| 84 |
static_assert(test_category<is_aggregate, |
| 85 |
unsigned>(false), ""); |
| 86 |
static_assert(test_category<is_aggregate, |
| 87 |
bool>(false), ""); |
| 88 |
static_assert(test_category<is_aggregate, |
| 89 |
float>(false), ""); |
| 90 |
static_assert(test_category<is_aggregate, |
| 91 |
double>(false), ""); |
| 92 |
static_assert(test_category<is_aggregate, |
| 93 |
EnumType>(false), ""); |
| 94 |
static_assert(test_category<is_aggregate, |
| 95 |
void>(false), ""); |
| 96 |
neg<AbstractClass, PolymorphicClass, ExplicitClass, char, unsigned, |
| 97 |
bool, float, double, void>(); |
| 98 |
#if __cplusplus > 201703L |
| 99 |
// In C++20 aggregates cannot have user-declared constructors. |
| 100 |
static_assert(test_category<is_aggregate, |
| 101 |
NoexceptMoveAssignClass>(false), ""); |
| 102 |
neg<NoexceptMoveAssignClass>(); |
| 103 |
#endif |
| 104 |
} |