[llvm] b4e9977 - Remove C++17 #ifdefs around the implicit conversion between StringRef and string_view
Benjamin Kramer via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 8 04:06:28 PDT 2022
Author: Benjamin Kramer
Date: 2022-08-08T12:59:23+02:00
New Revision: b4e9977fc18405d4a11cbaf1975bcadbf75920b8
URL: https://github.com/llvm/llvm-project/commit/b4e9977fc18405d4a11cbaf1975bcadbf75920b8
DIFF: https://github.com/llvm/llvm-project/commit/b4e9977fc18405d4a11cbaf1975bcadbf75920b8.diff
LOG: Remove C++17 #ifdefs around the implicit conversion between StringRef and string_view
This is no longer needed as LLVM is built with C++17 now. Also drop the
explicit conversion to std::string as the implicit conversion to
std::string_view gets picked first anyways.
Added:
Modified:
llvm/include/llvm/ADT/StringRef.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/ADT/StringRef.h b/llvm/include/llvm/ADT/StringRef.h
index 1ba92038dd75..1f7f91260751 100644
--- a/llvm/include/llvm/ADT/StringRef.h
+++ b/llvm/include/llvm/ADT/StringRef.h
@@ -19,18 +19,10 @@
#include <cstring>
#include <limits>
#include <string>
-#if __cplusplus > 201402L
#include <string_view>
-#endif
#include <type_traits>
#include <utility>
-// Declare the __builtin_strlen intrinsic for MSVC so it can be used in
-// constexpr context.
-#if defined(_MSC_VER)
-extern "C" size_t __builtin_strlen(const char *);
-#endif
-
namespace llvm {
class APInt;
@@ -77,21 +69,6 @@ namespace llvm {
return ::memcmp(Lhs,Rhs,Length);
}
- // Constexpr version of std::strlen.
- static constexpr size_t strLen(const char *Str) {
-#if __cplusplus > 201402L
- return std::char_traits<char>::length(Str);
-#elif __has_builtin(__builtin_strlen) || defined(__GNUC__) || \
- (defined(_MSC_VER) && _MSC_VER >= 1916)
- return __builtin_strlen(Str);
-#else
- const char *Begin = Str;
- while (*Str != '\0')
- ++Str;
- return Str - Begin;
-#endif
- }
-
public:
/// @name Constructors
/// @{
@@ -105,7 +82,7 @@ namespace llvm {
/// Construct a string ref from a cstring.
/*implicit*/ constexpr StringRef(const char *Str)
- : Data(Str), Length(Str ? strLen(Str) : 0) {}
+ : Data(Str), Length(Str ? std::char_traits<char>::length(Str) : 0) {}
/// Construct a string ref from a pointer and length.
/*implicit*/ constexpr StringRef(const char *data, size_t length)
@@ -115,11 +92,9 @@ namespace llvm {
/*implicit*/ StringRef(const std::string &Str)
: Data(Str.data()), Length(Str.length()) {}
-#if __cplusplus > 201402L
/// Construct a string ref from an std::string_view.
/*implicit*/ constexpr StringRef(std::string_view Str)
: Data(Str.data()), Length(Str.size()) {}
-#endif
/// @}
/// @name Iterators
@@ -261,13 +236,9 @@ namespace llvm {
/// @name Type Conversions
/// @{
- explicit operator std::string() const { return str(); }
-
-#if __cplusplus > 201402L
operator std::string_view() const {
return std::string_view(data(), size());
}
-#endif
/// @}
/// @name String Predicates
More information about the llvm-commits
mailing list