invoke_function_object.pass.cpp 1.5 KB

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