Eric Fiselier | 60b3df4 | 2014-12-23 05:54:34 +0000 | [diff] [blame] | 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 | |
Eric Fiselier | 45f63bc | 2015-07-22 04:14:38 +0000 | [diff] [blame] | 10 | // UNSUPPORTED: c++98, c++03 |
| 11 | |
Eric Fiselier | 60b3df4 | 2014-12-23 05:54:34 +0000 | [diff] [blame] | 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 | // http://llvm.org/bugs/show_bug.cgi?id=22003 |
| 20 | |
| 21 | #include <functional> |
| 22 | |
| 23 | struct DummyUnaryFunction |
| 24 | { |
| 25 | template <typename S> |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 26 | int operator()(S const & s) const { return 0; } |
Eric Fiselier | 60b3df4 | 2014-12-23 05:54:34 +0000 | [diff] [blame] | 27 | }; |
| 28 | |
| 29 | struct BadUnaryFunction |
| 30 | { |
| 31 | template <typename S> |
| 32 | constexpr int operator()(S const & s) 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 | |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 42 | int main(int argc, char* argv[]) |
Eric Fiselier | 60b3df4 | 2014-12-23 05:54:34 +0000 | [diff] [blame] | 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 | } |