[llvm] [ADT] Make StringRef std::string_view conversion operator constexpr. NFC (PR #77506)

via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 9 10:29:26 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-adt

Author: Luke Lau (lukel97)

<details>
<summary>Changes</summary>

This would allow us to compare StringRefs via std::string_view, avoiding having
to make the existing StringRef compare machinery constexpr for now, which we
could then use in #<!-- -->77442


---
Full diff: https://github.com/llvm/llvm-project/pull/77506.diff


1 Files Affected:

- (modified) llvm/include/llvm/ADT/StringRef.h (+2-2) 


``````````diff
diff --git a/llvm/include/llvm/ADT/StringRef.h b/llvm/include/llvm/ADT/StringRef.h
index d892333de391ce..1c6c96678b5d27 100644
--- a/llvm/include/llvm/ADT/StringRef.h
+++ b/llvm/include/llvm/ADT/StringRef.h
@@ -128,7 +128,7 @@ namespace llvm {
 
     /// data - Get a pointer to the start of the string (which may not be null
     /// terminated).
-    [[nodiscard]] const char *data() const { return Data; }
+    [[nodiscard]] constexpr const char *data() const { return Data; }
 
     /// empty - Check if the string is empty.
     [[nodiscard]] constexpr bool empty() const { return Length == 0; }
@@ -245,7 +245,7 @@ namespace llvm {
     /// @name Type Conversions
     /// @{
 
-    operator std::string_view() const {
+    constexpr operator std::string_view() const {
       return std::string_view(data(), size());
     }
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/77506


More information about the llvm-commits mailing list