[llvm] 2c1796b - [ADT] GCC 7 doesn't have constexpr char_traits, add a workaround

Benjamin Kramer via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 26 05:15:30 PDT 2022


Author: Benjamin Kramer
Date: 2022-08-26T14:11:21+02:00
New Revision: 2c1796b3d6c252e2fb7d17efb6089b0f0c4aa695

URL: https://github.com/llvm/llvm-project/commit/2c1796b3d6c252e2fb7d17efb6089b0f0c4aa695
DIFF: https://github.com/llvm/llvm-project/commit/2c1796b3d6c252e2fb7d17efb6089b0f0c4aa695.diff

LOG: [ADT] GCC 7 doesn't have constexpr char_traits, add a workaround

LLVM still supports GCC 7. This workaround can be removed when GCC 8
becomes the oldest supported GCC version.

Fixes #57057

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 1f7f912607515..25dcda02eae1d 100644
--- a/llvm/include/llvm/ADT/StringRef.h
+++ b/llvm/include/llvm/ADT/StringRef.h
@@ -82,7 +82,15 @@ namespace llvm {
 
     /// Construct a string ref from a cstring.
     /*implicit*/ constexpr StringRef(const char *Str)
-        : Data(Str), Length(Str ? std::char_traits<char>::length(Str) : 0) {}
+        : Data(Str), Length(Str ?
+    // GCC 7 doesn't have constexpr char_traits. Fall back to __builtin_strlen.
+#if defined(_GLIBCXX_RELEASE) && _GLIBCXX_RELEASE < 8
+                                __builtin_strlen(Str)
+#else
+                                std::char_traits<char>::length(Str)
+#endif
+                                : 0) {
+    }
 
     /// Construct a string ref from a pointer and length.
     /*implicit*/ constexpr StringRef(const char *data, size_t length)


        


More information about the llvm-commits mailing list