F_incomplete.pass.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. // <functional>
  9. // class function<R(ArgTypes...)>
  10. // template<class F> function(F);
  11. // Allow incomplete argument types in the __is_callable check
  12. #include <functional>
  13. #include <cassert>
  14. #include "test_macros.h"
  15. struct X{
  16. typedef std::function<void(X&)> callback_type;
  17. virtual ~X() {}
  18. private:
  19. callback_type _cb;
  20. };
  21. struct IncompleteReturnType {
  22. std::function<IncompleteReturnType ()> fn;
  23. };
  24. int called = 0;
  25. IncompleteReturnType test_fn() {
  26. ++called;
  27. IncompleteReturnType I;
  28. return I;
  29. }
  30. // See llvm.org/PR34298
  31. void test_pr34298()
  32. {
  33. static_assert(std::is_copy_constructible<IncompleteReturnType>::value, "");
  34. static_assert(std::is_copy_assignable<IncompleteReturnType>::value, "");
  35. {
  36. IncompleteReturnType X;
  37. X.fn = test_fn;
  38. const IncompleteReturnType& CX = X;
  39. IncompleteReturnType X2 = CX;
  40. assert(X2.fn);
  41. assert(called == 0);
  42. X2.fn();
  43. assert(called == 1);
  44. }
  45. {
  46. IncompleteReturnType Empty;
  47. IncompleteReturnType X2 = Empty;
  48. assert(!X2.fn);
  49. }
  50. }
  51. int main(int, char**) {
  52. test_pr34298();
  53. return 0;
  54. }