Index: llvm/include/llvm/ADT/StringRef.h =================================================================== --- llvm/include/llvm/ADT/StringRef.h +++ llvm/include/llvm/ADT/StringRef.h @@ -149,11 +149,11 @@ /// empty - Check if the string is empty. LLVM_NODISCARD - bool empty() const { return Length == 0; } + constexpr bool empty() const { return Length == 0; } /// size - Get the string size. LLVM_NODISCARD - size_t size() const { return Length; } + constexpr size_t size() const { return Length; } /// front - Get the first character in the string. LLVM_NODISCARD Index: llvm/unittests/ADT/StringRefTest.cpp =================================================================== --- llvm/unittests/ADT/StringRefTest.cpp +++ llvm/unittests/ADT/StringRefTest.cpp @@ -1092,10 +1092,14 @@ TEST(StringRefTest, StringLiteral) { constexpr StringRef StringRefs[] = {"Foo", "Bar"}; EXPECT_EQ(StringRef("Foo"), StringRefs[0]); + EXPECT_EQ(3u, (std::integral_constant::value)); + EXPECT_EQ(false, (std::integral_constant::value)); EXPECT_EQ(StringRef("Bar"), StringRefs[1]); constexpr StringLiteral Strings[] = {"Foo", "Bar"}; EXPECT_EQ(StringRef("Foo"), Strings[0]); + EXPECT_EQ(3u, (std::integral_constant::value)); + EXPECT_EQ(false, (std::integral_constant::value)); EXPECT_EQ(StringRef("Bar"), Strings[1]); }