From ee2f195dd3e40f49698ca4dc2666ec09c770e80d Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Tue, 30 May 2017 17:37:31 +0000 Subject: Vendor import of llvm trunk r304222: https://llvm.org/svn/llvm-project/llvm/trunk@304222 --- unittests/Support/ManagedStatic.cpp | 41 +++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'unittests/Support/ManagedStatic.cpp') diff --git a/unittests/Support/ManagedStatic.cpp b/unittests/Support/ManagedStatic.cpp index 153884ba42986..4e2e93036a83e 100644 --- a/unittests/Support/ManagedStatic.cpp +++ b/unittests/Support/ManagedStatic.cpp @@ -57,4 +57,45 @@ TEST(Initialize, MultipleThreads) { } #endif +namespace NestedStatics { +static ManagedStatic Ms1; +struct Nest { + Nest() { + ++(*Ms1); + } + + ~Nest() { + assert(Ms1.isConstructed()); + ++(*Ms1); + } +}; +static ManagedStatic Ms2; + +TEST(ManagedStaticTest, NestedStatics) { + EXPECT_FALSE(Ms1.isConstructed()); + EXPECT_FALSE(Ms2.isConstructed()); + + *Ms2; + EXPECT_TRUE(Ms1.isConstructed()); + EXPECT_TRUE(Ms2.isConstructed()); +} +} // namespace NestedStatics + +namespace CustomCreatorDeletor { +struct CustomCreate { + static void *call() { + void *Mem = std::malloc(sizeof(int)); + *((int *)Mem) = 42; + return Mem; + } +}; +struct CustomDelete { + static void call(void *P) { std::free(P); } +}; +static ManagedStatic Custom; +TEST(ManagedStaticTest, CustomCreatorDeletor) { + EXPECT_EQ(42, *Custom); +} +} // namespace CustomCreatorDeletor + } // anonymous namespace -- cgit v1.3