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 struct X{
21     typedef std::function<void(X&)> callback_type;
22     virtual ~X() {}
23 private:
24     callback_type _cb;
25 };
26 
27 struct IncompleteReturnType {
28   std::function<IncompleteReturnType ()> fn;
29 };
30 
31 
32 int called = 0;
33 IncompleteReturnType test_fn() {
34   ++called;
35   IncompleteReturnType I;
36   return I;
37 }
38 
39 // See llvm.org/PR34298
40 void test_pr34298()
41 {
42   static_assert(std::is_copy_constructible<IncompleteReturnType>::value, "");
43   static_assert(std::is_copy_assignable<IncompleteReturnType>::value, "");
44   {
45     IncompleteReturnType X;
46     X.fn = test_fn;
47     const IncompleteReturnType& CX = X;
48     IncompleteReturnType X2 = CX;
49     assert(X2.fn);
50     assert(called == 0);
51     X2.fn();
52     assert(called == 1);
53   }
54   {
55     IncompleteReturnType Empty;
56     IncompleteReturnType X2 = Empty;
57     assert(!X2.fn);
58   }
59 }
60 
61 int main(int, char**) {
62   test_pr34298();
63 
64   return 0;
65 }
66