FunctionRefTest.cpp 745 B

12345678910111213141516171819202122232425262728
  1. //===- llvm/unittest/ADT/MakeUniqueTest.cpp - make_unique unit tests ------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. #include "llvm/ADT/STLExtras.h"
  10. #include "gtest/gtest.h"
  11. using namespace llvm;
  12. namespace {
  13. // Ensure that copies of a function_ref copy the underlying state rather than
  14. // causing one function_ref to chain to the next.
  15. TEST(FunctionRefTest, Copy) {
  16. auto A = [] { return 1; };
  17. auto B = [] { return 2; };
  18. function_ref<int()> X = A;
  19. function_ref<int()> Y = X;
  20. X = B;
  21. EXPECT_EQ(1, Y());
  22. }
  23. }