Marshall Clow | 94611a8 | 2015-11-01 20:24:59 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | // type_traits |
| 11 | |
| 12 | // is_lvalue_reference |
| 13 | |
| 14 | // UNSUPPORTED: c++98, c++03 |
| 15 | |
| 16 | #include <type_traits> |
Marshall Clow | 55d741c | 2015-11-10 15:48:23 +0000 | [diff] [blame] | 17 | #include <cstddef> // for std::nullptr_t |
Marshall Clow | 94611a8 | 2015-11-01 20:24:59 +0000 | [diff] [blame] | 18 | #include "test_macros.h" |
| 19 | |
| 20 | template <class T> |
| 21 | void test_is_lvalue_reference() |
| 22 | { |
| 23 | static_assert( std::is_lvalue_reference<T>::value, ""); |
| 24 | static_assert( std::is_lvalue_reference<const T>::value, ""); |
| 25 | static_assert( std::is_lvalue_reference<volatile T>::value, ""); |
| 26 | static_assert( std::is_lvalue_reference<const volatile T>::value, ""); |
| 27 | #if TEST_STD_VER > 14 |
| 28 | static_assert( std::is_lvalue_reference_v<T>, ""); |
| 29 | static_assert( std::is_lvalue_reference_v<const T>, ""); |
| 30 | static_assert( std::is_lvalue_reference_v<volatile T>, ""); |
| 31 | static_assert( std::is_lvalue_reference_v<const volatile T>, ""); |
| 32 | #endif |
| 33 | } |
| 34 | |
| 35 | template <class T> |
| 36 | void test_is_not_lvalue_reference() |
| 37 | { |
| 38 | static_assert(!std::is_lvalue_reference<T>::value, ""); |
| 39 | static_assert(!std::is_lvalue_reference<const T>::value, ""); |
| 40 | static_assert(!std::is_lvalue_reference<volatile T>::value, ""); |
| 41 | static_assert(!std::is_lvalue_reference<const volatile T>::value, ""); |
| 42 | #if TEST_STD_VER > 14 |
| 43 | static_assert(!std::is_lvalue_reference_v<T>, ""); |
| 44 | static_assert(!std::is_lvalue_reference_v<const T>, ""); |
| 45 | static_assert(!std::is_lvalue_reference_v<volatile T>, ""); |
| 46 | static_assert(!std::is_lvalue_reference_v<const volatile T>, ""); |
| 47 | #endif |
| 48 | } |
| 49 | |
| 50 | class Empty |
| 51 | { |
| 52 | }; |
| 53 | |
| 54 | class NotEmpty |
| 55 | { |
| 56 | virtual ~NotEmpty(); |
| 57 | }; |
| 58 | |
| 59 | union Union {}; |
| 60 | |
| 61 | struct bit_zero |
| 62 | { |
| 63 | int : 0; |
| 64 | }; |
| 65 | |
| 66 | class Abstract |
| 67 | { |
| 68 | virtual ~Abstract() = 0; |
| 69 | }; |
| 70 | |
| 71 | enum Enum {zero, one}; |
Marshall Clow | 7490f53 | 2016-02-25 20:15:47 +0000 | [diff] [blame^] | 72 | struct incomplete_type; |
Marshall Clow | 94611a8 | 2015-11-01 20:24:59 +0000 | [diff] [blame] | 73 | |
| 74 | typedef void (*FunctionPtr)(); |
| 75 | |
| 76 | int main() |
| 77 | { |
| 78 | test_is_lvalue_reference<int&>(); |
| 79 | |
| 80 | test_is_not_lvalue_reference<std::nullptr_t>(); |
| 81 | test_is_not_lvalue_reference<void>(); |
| 82 | test_is_not_lvalue_reference<int>(); |
| 83 | test_is_not_lvalue_reference<int*>(); |
| 84 | test_is_not_lvalue_reference<int&&>(); |
| 85 | test_is_not_lvalue_reference<double>(); |
| 86 | test_is_not_lvalue_reference<const int*>(); |
| 87 | test_is_not_lvalue_reference<char[3]>(); |
| 88 | test_is_not_lvalue_reference<char[]>(); |
| 89 | test_is_not_lvalue_reference<Union>(); |
| 90 | test_is_not_lvalue_reference<Enum>(); |
| 91 | test_is_not_lvalue_reference<FunctionPtr>(); |
| 92 | test_is_not_lvalue_reference<Empty>(); |
| 93 | test_is_not_lvalue_reference<bit_zero>(); |
| 94 | test_is_not_lvalue_reference<NotEmpty>(); |
| 95 | test_is_not_lvalue_reference<Abstract>(); |
Marshall Clow | 7490f53 | 2016-02-25 20:15:47 +0000 | [diff] [blame^] | 96 | test_is_not_lvalue_reference<incomplete_type>(); |
Marshall Clow | 94611a8 | 2015-11-01 20:24:59 +0000 | [diff] [blame] | 97 | } |