X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=unittests%2FADT%2FOptionalTest.cpp;h=18b59e315818eaa84eb35464e702b131c9099c1d;hb=813f44a29fd0fd140127023222d0633e23783bcc;hp=4482d6157bbcae0fad431b1f66bba4ebc6a124e9;hpb=909a11120e899da103911ba16cc3972997445297;p=oota-llvm.git diff --git a/unittests/ADT/OptionalTest.cpp b/unittests/ADT/OptionalTest.cpp index 4482d6157bb..18b59e31581 100644 --- a/unittests/ADT/OptionalTest.cpp +++ b/unittests/ADT/OptionalTest.cpp @@ -183,10 +183,10 @@ struct MultiArgConstructor { explicit MultiArgConstructor(int x, bool positive) : x(x), y(positive ? x : -x) {} - MultiArgConstructor(const MultiArgConstructor &) LLVM_DELETED_FUNCTION; - MultiArgConstructor(MultiArgConstructor &&) LLVM_DELETED_FUNCTION; - MultiArgConstructor &operator=(const MultiArgConstructor &) LLVM_DELETED_FUNCTION; - MultiArgConstructor &operator=(MultiArgConstructor &&) LLVM_DELETED_FUNCTION; + MultiArgConstructor(const MultiArgConstructor &) = delete; + MultiArgConstructor(MultiArgConstructor &&) = delete; + MultiArgConstructor &operator=(const MultiArgConstructor &) = delete; + MultiArgConstructor &operator=(MultiArgConstructor &&) = delete; static unsigned Destructions; ~MultiArgConstructor() { @@ -324,15 +324,36 @@ TEST_F(OptionalTest, MoveOnlyAssigningAssignment) { EXPECT_EQ(1u, MoveOnly::Destructions); } -TEST_F(OptionalTest, MoveOnlyEmplace) { - Optional A; - MoveOnly::ResetCounts(); +struct Immovable { + static unsigned Constructions; + static unsigned Destructions; + int val; + explicit Immovable(int val) : val(val) { + ++Constructions; + } + ~Immovable() { + ++Destructions; + } + static void ResetCounts() { + Constructions = 0; + Destructions = 0; + } +private: + // This should disable all move/copy operations. + Immovable(Immovable&& other) = delete; +}; + +unsigned Immovable::Constructions = 0; +unsigned Immovable::Destructions = 0; + +TEST_F(OptionalTest, ImmovableEmplace) { + Optional A; + Immovable::ResetCounts(); A.emplace(4); EXPECT_TRUE((bool)A); EXPECT_EQ(4, A->val); - EXPECT_EQ(0u, MoveOnly::MoveConstructions); - EXPECT_EQ(0u, MoveOnly::MoveAssignments); - EXPECT_EQ(0u, MoveOnly::Destructions); + EXPECT_EQ(1u, Immovable::Constructions); + EXPECT_EQ(0u, Immovable::Destructions); } #if LLVM_HAS_RVALUE_REFERENCE_THIS @@ -356,5 +377,18 @@ TEST_F(OptionalTest, MoveGetValueOr) { #endif // LLVM_HAS_RVALUE_REFERENCE_THIS +TEST_F(OptionalTest, NoneComparison) { + Optional o; + EXPECT_EQ(o, None); + EXPECT_EQ(None, o); + EXPECT_FALSE(o != None); + EXPECT_FALSE(None != o); + o = 3; + EXPECT_FALSE(o == None); + EXPECT_FALSE(None == o); + EXPECT_TRUE(o != None); + EXPECT_TRUE(None != o); +} + } // end anonymous namespace