77 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++03, c++11, c++1410 11// <type_traits>12 13// template <class T> struct is_aggregate;14// template <class T> constexpr bool is_aggregate_v = is_aggregate<T>::value;15 16#include <type_traits>17#include "test_macros.h"18 19template <class T>20void test_true()21{22 static_assert( std::is_aggregate<T>::value, "");23 static_assert( std::is_aggregate<const T>::value, "");24 static_assert( std::is_aggregate<volatile T>::value, "");25 static_assert( std::is_aggregate<const volatile T>::value, "");26 static_assert( std::is_aggregate_v<T>, "");27 static_assert( std::is_aggregate_v<const T>, "");28 static_assert( std::is_aggregate_v<volatile T>, "");29 static_assert( std::is_aggregate_v<const volatile T>, "");30}31 32template <class T>33void test_false()34{35 static_assert(!std::is_aggregate<T>::value, "");36 static_assert(!std::is_aggregate<const T>::value, "");37 static_assert(!std::is_aggregate<volatile T>::value, "");38 static_assert(!std::is_aggregate<const volatile T>::value, "");39 static_assert(!std::is_aggregate_v<T>, "");40 static_assert(!std::is_aggregate_v<const T>, "");41 static_assert(!std::is_aggregate_v<volatile T>, "");42 static_assert(!std::is_aggregate_v<const volatile T>, "");43}44 45struct Aggregate {};46struct HasCons { HasCons(int); };47struct HasPriv {48 void PreventUnusedPrivateMemberWarning();49private:50 int x;51};52struct Union { int x; void* y; };53 54 55int main(int, char**)56{57 {58 test_false<void>();59 test_false<int>();60 test_false<void*>();61 test_false<void()>();62 test_false<void() const>();63 test_false<void(Aggregate::*)(int) const>();64 test_false<Aggregate&>();65 test_false<HasCons>();66 test_false<HasPriv>();67 }68 {69 test_true<Aggregate>();70 test_true<Aggregate[]>();71 test_true<Aggregate[42][101]>();72 test_true<Union>();73 }74 75 return 0;76}77