| 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 | // UNSUPPORTED: c++03 |
| 10 | |
| 11 | // <functional> |
| 12 | |
| 13 | // template<CopyConstructible Fn, CopyConstructible... Types> |
| 14 | // unspecified bind(Fn, Types...); |
| 15 | // template<Returnable R, CopyConstructible Fn, CopyConstructible... Types> |
| 16 | // unspecified bind(Fn, Types...); |
| 17 | |
| 18 | // https://llvm.org/PR22003 |
| 19 | |
| 20 | #include <functional> |
| 21 | |
| 22 | #include "test_macros.h" |
| 23 | |
| 24 | struct DummyUnaryFunction |
| 25 | { |
| 26 | template <typename S> |
| 27 | int operator()(S const &) const { return 0; } |
| 28 | }; |
| 29 | |
| 30 | struct BadUnaryFunction |
| 31 | { |
| 32 | template <typename S> |
| 33 | constexpr int operator()(S const &) const |
| 34 | { |
| 35 | // Trigger a compile error if this function is instantiated. |
| 36 | // The constexpr is needed so that it is instantiated while checking |
| 37 | // __invoke_of<BadUnaryFunction &, ...>. |
| 38 | static_assert(!std::is_same<S, S>::value, "Shit" ); |
| 39 | return 0; |
| 40 | } |
| 41 | }; |
| 42 | |
| 43 | int main(int, char**) |
| 44 | { |
| 45 | // Check that BadUnaryFunction::operator()(S const &) is not |
| 46 | // instantiated when checking if BadUnaryFunction is a nested bind |
| 47 | // expression during b(0). See PR22003. |
| 48 | auto b = std::bind(f: DummyUnaryFunction(), args: BadUnaryFunction()); |
| 49 | b(0); |
| 50 | auto b2 = std::bind<long>(f: DummyUnaryFunction(), args: BadUnaryFunction()); |
| 51 | b2(0); |
| 52 | |
| 53 | return 0; |
| 54 | } |
| 55 | |