82 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// type_traits10 11// add_pointer12// If T names a referenceable type or a (possibly cv-qualified) void type then13// the member typedef type shall name the same type as remove_reference_t<T>*;14// otherwise, type shall name T.15 16#include <type_traits>17#include "test_macros.h"18 19template <class T, class U>20void test_add_pointer()21{22 ASSERT_SAME_TYPE(U, typename std::add_pointer<T>::type);23#if TEST_STD_VER > 1124 ASSERT_SAME_TYPE(U, std::add_pointer_t<T>);25#endif26}27 28template <class F>29void test_function0()30{31 ASSERT_SAME_TYPE(F*, typename std::add_pointer<F>::type);32#if TEST_STD_VER > 1133 ASSERT_SAME_TYPE(F*, std::add_pointer_t<F>);34#endif35}36 37template <class F>38void test_function1()39{40 ASSERT_SAME_TYPE(F, typename std::add_pointer<F>::type);41#if TEST_STD_VER > 1142 ASSERT_SAME_TYPE(F, std::add_pointer_t<F>);43#endif44}45 46struct Foo {};47 48int main(int, char**)49{50 test_add_pointer<void, void*>();51 test_add_pointer<int, int*>();52 test_add_pointer<int[3], int(*)[3]>();53 test_add_pointer<int&, int*>();54 test_add_pointer<const int&, const int*>();55 test_add_pointer<int*, int**>();56 test_add_pointer<const int*, const int**>();57 test_add_pointer<Foo, Foo*>();58 59// LWG 2101 specifically talks about add_pointer and functions.60// The term of art is "a referenceable type", which a cv- or ref-qualified function is not.61 test_function0<void()>();62#if TEST_STD_VER >= 1163 test_function1<void() const>();64 test_function1<void() &>();65 test_function1<void() &&>();66 test_function1<void() const &>();67 test_function1<void() const &&>();68#endif69 70// But a cv- or ref-qualified member function *is* "a referenceable type"71 test_function0<void (Foo::*)()>();72#if TEST_STD_VER >= 1173 test_function0<void (Foo::*)() const>();74 test_function0<void (Foo::*)() &>();75 test_function0<void (Foo::*)() &&>();76 test_function0<void (Foo::*)() const &>();77 test_function0<void (Foo::*)() const &&>();78#endif79 80 return 0;81}82