[llvm] r286141 - Add tests for r286139.

Jordan Rose via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 7 12:40:17 PST 2016


Author: jrose
Date: Mon Nov  7 14:40:16 2016
New Revision: 286141

URL: http://llvm.org/viewvc/llvm-project?rev=286141&view=rev
Log:
Add tests for r286139.

Modified:
    llvm/trunk/unittests/ADT/StringRefTest.cpp

Modified: llvm/trunk/unittests/ADT/StringRefTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/StringRefTest.cpp?rev=286141&r1=286140&r2=286141&view=diff
==============================================================================
--- llvm/trunk/unittests/ADT/StringRefTest.cpp (original)
+++ llvm/trunk/unittests/ADT/StringRefTest.cpp Mon Nov  7 14:40:16 2016
@@ -32,6 +32,34 @@ std::ostream &operator<<(std::ostream &O
 
 }
 
+// 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<StringRef, std::string>::value,
+    "Assigning from prvalue std::string");
+static_assert(
+    !std::is_assignable<StringRef, std::string &&>::value,
+    "Assigning from xvalue std::string");
+static_assert(
+    std::is_assignable<StringRef, std::string &>::value,
+    "Assigning from lvalue std::string");
+static_assert(
+    std::is_assignable<StringRef, const char *>::value,
+    "Assigning from prvalue C string");
+static_assert(
+    std::is_assignable<StringRef, const char * &&>::value,
+    "Assigning from xvalue C string");
+static_assert(
+    std::is_assignable<StringRef, const char * &>::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";




More information about the llvm-commits mailing list