]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_function_object.pass.cpp
Vendor import of libc++ trunk r300422:
[FreeBSD/FreeBSD.git] / test / std / utilities / function.objects / bind / func.bind / func.bind.bind / invoke_function_object.pass.cpp
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 // UNSUPPORTED: c++98, c++03
11
12 // <functional>
13
14 // template<CopyConstructible Fn, CopyConstructible... Types>
15 //   unspecified bind(Fn, Types...);
16 // template<Returnable R, CopyConstructible Fn, CopyConstructible... Types>
17 //   unspecified bind(Fn, Types...);
18
19 // https://bugs.llvm.org/show_bug.cgi?id=22003
20
21 #include <functional>
22
23 struct DummyUnaryFunction
24 {
25     template <typename S>
26     int operator()(S const &) const { return 0; }
27 };
28
29 struct BadUnaryFunction
30 {
31     template <typename S>
32     constexpr int operator()(S const &) const
33     {
34         // Trigger a compile error if this function is instantiated.
35         // The constexpr is needed so that it is instantiated while checking
36         // __invoke_of<BadUnaryFunction &, ...>.
37         static_assert(!std::is_same<S, S>::value, "Shit");
38         return 0;
39     }
40 };
41
42 int main()
43 {
44     // Check that BadUnaryFunction::operator()(S const &) is not
45     // instantiated when checking if BadUnaryFunction is a nested bind
46     // expression during b(0). See PR22003.
47     auto b = std::bind(DummyUnaryFunction(), BadUnaryFunction());
48     b(0);
49     auto b2 = std::bind<long>(DummyUnaryFunction(), BadUnaryFunction());
50     b2(0);
51 }