194611a888b69dabe99f8fe30867d0ebd78854759Marshall Clow//===----------------------------------------------------------------------===// 294611a888b69dabe99f8fe30867d0ebd78854759Marshall Clow// 394611a888b69dabe99f8fe30867d0ebd78854759Marshall Clow// The LLVM Compiler Infrastructure 494611a888b69dabe99f8fe30867d0ebd78854759Marshall Clow// 594611a888b69dabe99f8fe30867d0ebd78854759Marshall Clow// This file is dual licensed under the MIT and the University of Illinois Open 694611a888b69dabe99f8fe30867d0ebd78854759Marshall Clow// Source Licenses. See LICENSE.TXT for details. 794611a888b69dabe99f8fe30867d0ebd78854759Marshall Clow// 894611a888b69dabe99f8fe30867d0ebd78854759Marshall Clow//===----------------------------------------------------------------------===// 994611a888b69dabe99f8fe30867d0ebd78854759Marshall Clow 1094611a888b69dabe99f8fe30867d0ebd78854759Marshall Clow// type_traits 1194611a888b69dabe99f8fe30867d0ebd78854759Marshall Clow 1294611a888b69dabe99f8fe30867d0ebd78854759Marshall Clow// is_function 1394611a888b69dabe99f8fe30867d0ebd78854759Marshall Clow 1494611a888b69dabe99f8fe30867d0ebd78854759Marshall Clow#include <type_traits> 1555d741c32e72234c022c728f24ccafb80ab8b485Marshall Clow#include <cstddef> // for std::nullptr_t 162c477cb41afd22162ab5ac671eea3cb78cdc2d6cEric Fiselier 1794611a888b69dabe99f8fe30867d0ebd78854759Marshall Clow#include "test_macros.h" 1894611a888b69dabe99f8fe30867d0ebd78854759Marshall Clow 194bd682bf5d3e8eaaad35c7b1857f013172c0a082Eric Fiselier// NOTE: On Windows the function `test_is_function<void()>` and 204bd682bf5d3e8eaaad35c7b1857f013172c0a082Eric Fiselier// `test_is_function<void() noexcept> has the same mangled despite being 214bd682bf5d3e8eaaad35c7b1857f013172c0a082Eric Fiselier// a distinct instantiation. This causes Clang to emit an error. However 224bd682bf5d3e8eaaad35c7b1857f013172c0a082Eric Fiselier// structs do not have this problem. 234bd682bf5d3e8eaaad35c7b1857f013172c0a082Eric Fiselier 2494611a888b69dabe99f8fe30867d0ebd78854759Marshall Clowtemplate <class T> 254bd682bf5d3e8eaaad35c7b1857f013172c0a082Eric Fiselierstruct test_is_function { 2694611a888b69dabe99f8fe30867d0ebd78854759Marshall Clow static_assert( std::is_function<T>::value, ""); 2794611a888b69dabe99f8fe30867d0ebd78854759Marshall Clow static_assert( std::is_function<const T>::value, ""); 2894611a888b69dabe99f8fe30867d0ebd78854759Marshall Clow static_assert( std::is_function<volatile T>::value, ""); 2994611a888b69dabe99f8fe30867d0ebd78854759Marshall Clow static_assert( std::is_function<const volatile T>::value, ""); 3094611a888b69dabe99f8fe30867d0ebd78854759Marshall Clow#if TEST_STD_VER > 14 3194611a888b69dabe99f8fe30867d0ebd78854759Marshall Clow static_assert( std::is_function_v<T>, ""); 3294611a888b69dabe99f8fe30867d0ebd78854759Marshall Clow static_assert( std::is_function_v<const T>, ""); 3394611a888b69dabe99f8fe30867d0ebd78854759Marshall Clow static_assert( std::is_function_v<volatile T>, ""); 3494611a888b69dabe99f8fe30867d0ebd78854759Marshall Clow static_assert( std::is_function_v<const volatile T>, ""); 3594611a888b69dabe99f8fe30867d0ebd78854759Marshall Clow#endif 364bd682bf5d3e8eaaad35c7b1857f013172c0a082Eric Fiselier}; 3794611a888b69dabe99f8fe30867d0ebd78854759Marshall Clow 3894611a888b69dabe99f8fe30867d0ebd78854759Marshall Clowtemplate <class T> 394bd682bf5d3e8eaaad35c7b1857f013172c0a082Eric Fiselierstruct test_is_not_function { 4094611a888b69dabe99f8fe30867d0ebd78854759Marshall Clow static_assert(!std::is_function<T>::value, ""); 4194611a888b69dabe99f8fe30867d0ebd78854759Marshall Clow static_assert(!std::is_function<const T>::value, ""); 4294611a888b69dabe99f8fe30867d0ebd78854759Marshall Clow static_assert(!std::is_function<volatile T>::value, ""); 4394611a888b69dabe99f8fe30867d0ebd78854759Marshall Clow static_assert(!std::is_function<const volatile T>::value, ""); 4494611a888b69dabe99f8fe30867d0ebd78854759Marshall Clow#if TEST_STD_VER > 14 4594611a888b69dabe99f8fe30867d0ebd78854759Marshall Clow static_assert(!std::is_function_v<T>, ""); 4694611a888b69dabe99f8fe30867d0ebd78854759Marshall Clow static_assert(!std::is_function_v<const T>, ""); 4794611a888b69dabe99f8fe30867d0ebd78854759Marshall Clow static_assert(!std::is_function_v<volatile T>, ""); 4894611a888b69dabe99f8fe30867d0ebd78854759Marshall Clow static_assert(!std::is_function_v<const volatile T>, ""); 4994611a888b69dabe99f8fe30867d0ebd78854759Marshall Clow#endif 504bd682bf5d3e8eaaad35c7b1857f013172c0a082Eric Fiselier}; 5194611a888b69dabe99f8fe30867d0ebd78854759Marshall Clow 5294611a888b69dabe99f8fe30867d0ebd78854759Marshall Clowclass Empty 5394611a888b69dabe99f8fe30867d0ebd78854759Marshall Clow{ 5494611a888b69dabe99f8fe30867d0ebd78854759Marshall Clow}; 5594611a888b69dabe99f8fe30867d0ebd78854759Marshall Clow 5694611a888b69dabe99f8fe30867d0ebd78854759Marshall Clowclass NotEmpty 5794611a888b69dabe99f8fe30867d0ebd78854759Marshall Clow{ 5894611a888b69dabe99f8fe30867d0ebd78854759Marshall Clow virtual ~NotEmpty(); 5994611a888b69dabe99f8fe30867d0ebd78854759Marshall Clow}; 6094611a888b69dabe99f8fe30867d0ebd78854759Marshall Clow 6194611a888b69dabe99f8fe30867d0ebd78854759Marshall Clowunion Union {}; 6294611a888b69dabe99f8fe30867d0ebd78854759Marshall Clow 6394611a888b69dabe99f8fe30867d0ebd78854759Marshall Clowstruct bit_zero 6494611a888b69dabe99f8fe30867d0ebd78854759Marshall Clow{ 6594611a888b69dabe99f8fe30867d0ebd78854759Marshall Clow int : 0; 6694611a888b69dabe99f8fe30867d0ebd78854759Marshall Clow}; 6794611a888b69dabe99f8fe30867d0ebd78854759Marshall Clow 6894611a888b69dabe99f8fe30867d0ebd78854759Marshall Clowclass Abstract 6994611a888b69dabe99f8fe30867d0ebd78854759Marshall Clow{ 7094611a888b69dabe99f8fe30867d0ebd78854759Marshall Clow virtual ~Abstract() = 0; 7194611a888b69dabe99f8fe30867d0ebd78854759Marshall Clow}; 7294611a888b69dabe99f8fe30867d0ebd78854759Marshall Clow 7394611a888b69dabe99f8fe30867d0ebd78854759Marshall Clowenum Enum {zero, one}; 747490f53118156f446b61583b7f0af0847b5942d7Marshall Clowstruct incomplete_type; 7594611a888b69dabe99f8fe30867d0ebd78854759Marshall Clow 7694611a888b69dabe99f8fe30867d0ebd78854759Marshall Clowtypedef void (*FunctionPtr)(); 7794611a888b69dabe99f8fe30867d0ebd78854759Marshall Clow 7894611a888b69dabe99f8fe30867d0ebd78854759Marshall Clowint main() 7994611a888b69dabe99f8fe30867d0ebd78854759Marshall Clow{ 80a686caad209c0475fd69346fe841ebb67a6eb06eStephan T. Lavavej test_is_function<void(void)>(); 81a686caad209c0475fd69346fe841ebb67a6eb06eStephan T. Lavavej test_is_function<int(int)>(); 82a686caad209c0475fd69346fe841ebb67a6eb06eStephan T. Lavavej test_is_function<int(int, double)>(); 83a686caad209c0475fd69346fe841ebb67a6eb06eStephan T. Lavavej test_is_function<int(Abstract *)>(); 84a686caad209c0475fd69346fe841ebb67a6eb06eStephan T. Lavavej test_is_function<void(...)>(); 8584acb1ec3f7d5e0f37d7176697c2fa876c413407Eric Fiselier 862c477cb41afd22162ab5ac671eea3cb78cdc2d6cEric Fiselier test_is_not_function<std::nullptr_t>(); 872c477cb41afd22162ab5ac671eea3cb78cdc2d6cEric Fiselier test_is_not_function<void>(); 882c477cb41afd22162ab5ac671eea3cb78cdc2d6cEric Fiselier test_is_not_function<int>(); 892c477cb41afd22162ab5ac671eea3cb78cdc2d6cEric Fiselier test_is_not_function<int&>(); 902c477cb41afd22162ab5ac671eea3cb78cdc2d6cEric Fiselier test_is_not_function<int&&>(); 912c477cb41afd22162ab5ac671eea3cb78cdc2d6cEric Fiselier test_is_not_function<int*>(); 922c477cb41afd22162ab5ac671eea3cb78cdc2d6cEric Fiselier test_is_not_function<double>(); 932c477cb41afd22162ab5ac671eea3cb78cdc2d6cEric Fiselier test_is_not_function<char[3]>(); 942c477cb41afd22162ab5ac671eea3cb78cdc2d6cEric Fiselier test_is_not_function<char[]>(); 952c477cb41afd22162ab5ac671eea3cb78cdc2d6cEric Fiselier test_is_not_function<Union>(); 962c477cb41afd22162ab5ac671eea3cb78cdc2d6cEric Fiselier test_is_not_function<Enum>(); 972c477cb41afd22162ab5ac671eea3cb78cdc2d6cEric Fiselier test_is_not_function<FunctionPtr>(); // function pointer is not a function 982c477cb41afd22162ab5ac671eea3cb78cdc2d6cEric Fiselier test_is_not_function<Empty>(); 992c477cb41afd22162ab5ac671eea3cb78cdc2d6cEric Fiselier test_is_not_function<bit_zero>(); 1002c477cb41afd22162ab5ac671eea3cb78cdc2d6cEric Fiselier test_is_not_function<NotEmpty>(); 1012c477cb41afd22162ab5ac671eea3cb78cdc2d6cEric Fiselier test_is_not_function<Abstract>(); 1022c477cb41afd22162ab5ac671eea3cb78cdc2d6cEric Fiselier test_is_not_function<Abstract*>(); 1032c477cb41afd22162ab5ac671eea3cb78cdc2d6cEric Fiselier test_is_not_function<incomplete_type>(); 1042c477cb41afd22162ab5ac671eea3cb78cdc2d6cEric Fiselier 1052c477cb41afd22162ab5ac671eea3cb78cdc2d6cEric Fiselier#if TEST_STD_VER >= 11 1062c477cb41afd22162ab5ac671eea3cb78cdc2d6cEric Fiselier test_is_function<void() noexcept>(); 1072c477cb41afd22162ab5ac671eea3cb78cdc2d6cEric Fiselier test_is_function<void() const && noexcept>(); 1082c477cb41afd22162ab5ac671eea3cb78cdc2d6cEric Fiselier#endif 10994611a888b69dabe99f8fe30867d0ebd78854759Marshall Clow} 110