[PATCH] D115395: ADT: Make StringRef::size() and StringRef::empty() constexpr
Duncan P. N. Exon Smith via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 8 16:15:42 PST 2021
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9911589f5d4a: ADT: Make StringRef::size() and StringRef::empty() constexpr (authored by dexonsmith).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D115395/new/
https://reviews.llvm.org/D115395
Files:
llvm/include/llvm/ADT/StringRef.h
llvm/unittests/ADT/StringRefTest.cpp
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<size_t, StringRefs[0].size()>::value));
+ EXPECT_EQ(false, (std::integral_constant<bool, StringRefs[0].empty()>::value));
EXPECT_EQ(StringRef("Bar"), StringRefs[1]);
constexpr StringLiteral Strings[] = {"Foo", "Bar"};
EXPECT_EQ(StringRef("Foo"), Strings[0]);
+ EXPECT_EQ(3u, (std::integral_constant<size_t, Strings[0].size()>::value));
+ EXPECT_EQ(false, (std::integral_constant<bool, Strings[0].empty()>::value));
EXPECT_EQ(StringRef("Bar"), Strings[1]);
}
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115395.392968.patch
Type: text/x-patch
Size: 1493 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211209/06284241/attachment.bin>
More information about the llvm-commits
mailing list