Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 2544262

Browse files
committed
Add tests for r286139.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286141 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent b2fa9f7 commit 2544262

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

unittests/ADT/StringRefTest.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,34 @@ std::ostream &operator<<(std::ostream &OS,
3232

3333
}
3434

35+
// Check that we can't accidentally assign a temporary std::string to a
36+
// StringRef. (Unfortunately we can't make use of the same thing with
37+
// constructors.)
38+
//
39+
// Disable this check under MSVC; even MSVC 2015 isn't consistent between
40+
// std::is_assignable and actually writing such an assignment.
41+
#if !defined(_MSC_VER)
42+
static_assert(
43+
!std::is_assignable<StringRef, std::string>::value,
44+
"Assigning from prvalue std::string");
45+
static_assert(
46+
!std::is_assignable<StringRef, std::string &&>::value,
47+
"Assigning from xvalue std::string");
48+
static_assert(
49+
std::is_assignable<StringRef, std::string &>::value,
50+
"Assigning from lvalue std::string");
51+
static_assert(
52+
std::is_assignable<StringRef, const char *>::value,
53+
"Assigning from prvalue C string");
54+
static_assert(
55+
std::is_assignable<StringRef, const char * &&>::value,
56+
"Assigning from xvalue C string");
57+
static_assert(
58+
std::is_assignable<StringRef, const char * &>::value,
59+
"Assigning from lvalue C string");
60+
#endif
61+
62+
3563
namespace {
3664
TEST(StringRefTest, Construction) {
3765
EXPECT_EQ("", StringRef());
@@ -40,6 +68,14 @@ TEST(StringRefTest, Construction) {
4068
EXPECT_EQ("hello", StringRef(std::string("hello")));
4169
}
4270

71+
TEST(StringRefTest, EmptyInitializerList) {
72+
StringRef S = {};
73+
EXPECT_TRUE(S.empty());
74+
75+
S = {};
76+
EXPECT_TRUE(S.empty());
77+
}
78+
4379
TEST(StringRefTest, Iteration) {
4480
StringRef S("hello");
4581
const char *p = "hello";

0 commit comments

Comments
 (0)