[llvm] [ADT] Make StringRef std::string_view conversion operator constexpr. NFC (PR #77506)
Luke Lau via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 9 10:28:55 PST 2024
https://github.com/lukel97 created https://github.com/llvm/llvm-project/pull/77506
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
>From 56b76f9f0ff683be0ff95ebee7476e745488b156 Mon Sep 17 00:00:00 2001
From: Luke Lau <luke at igalia.com>
Date: Wed, 10 Jan 2024 01:25:39 +0700
Subject: [PATCH] [ADT] Make StringRef std::string_view conversion operator
constexpr. NFC
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
---
llvm/include/llvm/ADT/StringRef.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
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());
}
More information about the llvm-commits
mailing list