From: Jordan Rose Date: Mon, 7 Nov 2016 20:40:16 +0000 (+0000) Subject: Add tests for r286139. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fd34be2ddd29cd4390319739e4b8945588c4f7d7;p=llvm Add tests for r286139. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286141 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/unittests/ADT/StringRefTest.cpp b/unittests/ADT/StringRefTest.cpp index ca6b011d695..9c65a4b3589 100644 --- a/unittests/ADT/StringRefTest.cpp +++ b/unittests/ADT/StringRefTest.cpp @@ -32,6 +32,34 @@ std::ostream &operator<<(std::ostream &OS, } +// Check that we can't accidentally assign a temporary std::string to a +// StringRef. (Unfortunately we can't make use of the same thing with +// constructors.) +// +// Disable this check under MSVC; even MSVC 2015 isn't consistent between +// std::is_assignable and actually writing such an assignment. +#if !defined(_MSC_VER) +static_assert( + !std::is_assignable::value, + "Assigning from prvalue std::string"); +static_assert( + !std::is_assignable::value, + "Assigning from xvalue std::string"); +static_assert( + std::is_assignable::value, + "Assigning from lvalue std::string"); +static_assert( + std::is_assignable::value, + "Assigning from prvalue C string"); +static_assert( + std::is_assignable::value, + "Assigning from xvalue C string"); +static_assert( + std::is_assignable::value, + "Assigning from lvalue C string"); +#endif + + namespace { TEST(StringRefTest, Construction) { EXPECT_EQ("", StringRef()); @@ -40,6 +68,14 @@ TEST(StringRefTest, Construction) { EXPECT_EQ("hello", StringRef(std::string("hello"))); } +TEST(StringRefTest, EmptyInitializerList) { + StringRef S = {}; + EXPECT_TRUE(S.empty()); + + S = {}; + EXPECT_TRUE(S.empty()); +} + TEST(StringRefTest, Iteration) { StringRef S("hello"); const char *p = "hello";