| 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-exception |
| 6 |
// |
| 7 |
//===----------------------------------------------------------------------===// |
| 8 |
// |
| 9 |
|
| 10 |
// __libcpp_is_referenceable<Tp> |
| 11 |
// |
| 12 |
// [defns.referenceable] defines "a referenceable type" as: |
| 13 |
// An object type, a function type that does not have cv-qualifiers |
| 14 |
// or a ref-qualifier, or a reference type. |
| 15 |
// |
| 16 |
|
| 17 |
#include <type_traits> |
| 18 |
#include <cassert> |
| 19 |
|
| 20 |
#include "test_macros.h" |
| 21 |
|
| 22 |
struct Foo {}; |
| 23 |
|
| 24 |
static_assert((!std::__libcpp_is_referenceable<void>::value), ""); |
| 25 |
static_assert((std::__libcpp_is_referenceable<int>::value), ""); |
| 26 |
static_assert((std::__libcpp_is_referenceable<int[3]>::value), ""); |
| 27 |
static_assert((std::__libcpp_is_referenceable<int[]>::value), ""); |
| 28 |
static_assert((std::__libcpp_is_referenceable<int&>::value), ""); |
| 29 |
static_assert((std::__libcpp_is_referenceable<const int&>::value), ""); |
| 30 |
static_assert((std::__libcpp_is_referenceable<int*>::value), ""); |
| 31 |
static_assert((std::__libcpp_is_referenceable<const int*>::value), ""); |
| 32 |
static_assert((std::__libcpp_is_referenceable<Foo>::value), ""); |
| 33 |
static_assert((std::__libcpp_is_referenceable<const Foo>::value), ""); |
| 34 |
static_assert((std::__libcpp_is_referenceable<Foo&>::value), ""); |
| 35 |
static_assert((std::__libcpp_is_referenceable<const Foo&>::value), ""); |
| 36 |
|
| 37 |
static_assert((std::__libcpp_is_referenceable<int __attribute__((__vector_size__(8)))>::value), ""); |
| 38 |
static_assert((std::__libcpp_is_referenceable<const int __attribute__((__vector_size__(8)))>::value), ""); |
| 39 |
static_assert((std::__libcpp_is_referenceable<float __attribute__((__vector_size__(16)))>::value), ""); |
| 40 |
static_assert((std::__libcpp_is_referenceable<const float __attribute__((__vector_size__(16)))>::value), ""); |
| 41 |
|
| 42 |
// Functions without cv-qualifiers are referenceable |
| 43 |
static_assert((std::__libcpp_is_referenceable<void()>::value), ""); |
| 44 |
|
| 45 |
static_assert((std::__libcpp_is_referenceable<void(int)>::value), ""); |
| 46 |
|
| 47 |
static_assert((std::__libcpp_is_referenceable<void(int, float)>::value), ""); |
| 48 |
|
| 49 |
static_assert((std::__libcpp_is_referenceable<void(int, float, Foo&)>::value), ""); |
| 50 |
|
| 51 |
static_assert((std::__libcpp_is_referenceable<void(...)>::value), ""); |
| 52 |
|
| 53 |
static_assert((std::__libcpp_is_referenceable<void(int, ...)>::value), ""); |
| 54 |
|
| 55 |
static_assert((std::__libcpp_is_referenceable<void(int, float, ...)>::value), ""); |
| 56 |
|
| 57 |
static_assert((std::__libcpp_is_referenceable<void(int, float, Foo&, ...)>::value), ""); |
| 58 |
|
| 59 |
// member functions with or without cv-qualifiers are referenceable |
| 60 |
static_assert((std::__libcpp_is_referenceable<void (Foo::*)()>::value), ""); |
| 61 |
static_assert((std::__libcpp_is_referenceable<void (Foo::*)() const>::value), ""); |
| 62 |
|
| 63 |
static_assert((std::__libcpp_is_referenceable<void (Foo::*)(int)>::value), ""); |
| 64 |
static_assert((std::__libcpp_is_referenceable<void (Foo::*)(int) const>::value), ""); |
| 65 |
|
| 66 |
static_assert((std::__libcpp_is_referenceable<void (Foo::*)(int, float)>::value), ""); |
| 67 |
static_assert((std::__libcpp_is_referenceable<void (Foo::*)(int, float) const>::value), ""); |
| 68 |
|
| 69 |
static_assert((std::__libcpp_is_referenceable<void (Foo::*)(int, float, Foo&)>::value), ""); |
| 70 |
static_assert((std::__libcpp_is_referenceable<void (Foo::*)(int, float, Foo&) const>::value), ""); |
| 71 |
|
| 72 |
static_assert((std::__libcpp_is_referenceable<void (Foo::*)(...)>::value), ""); |
| 73 |
static_assert((std::__libcpp_is_referenceable<void (Foo::*)(...) const>::value), ""); |
| 74 |
|
| 75 |
static_assert((std::__libcpp_is_referenceable<void (Foo::*)(int, ...)>::value), ""); |
| 76 |
static_assert((std::__libcpp_is_referenceable<void (Foo::*)(int, ...) const>::value), ""); |
| 77 |
|
| 78 |
static_assert((std::__libcpp_is_referenceable<void (Foo::*)(int, float, ...)>::value), ""); |
| 79 |
static_assert((std::__libcpp_is_referenceable<void (Foo::*)(int, float, ...) const>::value), ""); |
| 80 |
|
| 81 |
static_assert((std::__libcpp_is_referenceable<void (Foo::*)(int, float, Foo&, ...)>::value), ""); |
| 82 |
static_assert((std::__libcpp_is_referenceable<void (Foo::*)(int, float, Foo&, ...) const>::value), ""); |