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 // <functional> 10 11 // class function<R(ArgTypes...)> 12 13 // template<class F> function(F); 14 15 // Allow incomplete argument types in the __is_callable check 16 17 #include <functional> 18 #include <cassert> 19 20 #include "test_macros.h" 21 22 struct X{ 23 typedef std::function<void(X&)> callback_type; 24 virtual ~X() {} 25 private: 26 callback_type _cb; 27 }; 28 29 struct IncompleteReturnType { 30 std::function<IncompleteReturnType ()> fn; 31 }; 32 33 34 int called = 0; 35 IncompleteReturnType test_fn() { 36 ++called; 37 IncompleteReturnType I; 38 return I; 39 } 40 41 // See llvm.org/PR34298 42 void test_pr34298() 43 { 44 static_assert(std::is_copy_constructible<IncompleteReturnType>::value, ""); 45 static_assert(std::is_copy_assignable<IncompleteReturnType>::value, ""); 46 { 47 IncompleteReturnType X; 48 X.fn = test_fn; 49 const IncompleteReturnType& CX = X; 50 IncompleteReturnType X2 = CX; 51 assert(X2.fn); 52 assert(called == 0); 53 X2.fn(); 54 assert(called == 1); 55 } 56 { 57 IncompleteReturnType Empty; 58 IncompleteReturnType X2 = Empty; 59 assert(!X2.fn); 60 } 61 } 62 63 int main(int, char**) { 64 test_pr34298(); 65 66 return 0; 67 } 68