[ADT] GCC 7 doesn't have constexpr char_traits, add a workaround
authorBenjamin Kramer <benny.kra@googlemail.com>
Fri, 26 Aug 2022 12:11:21 +0000 (14:11 +0200)
committerBenjamin Kramer <benny.kra@googlemail.com>
Fri, 26 Aug 2022 12:11:21 +0000 (14:11 +0200)
LLVM still supports GCC 7. This workaround can be removed when GCC 8
becomes the oldest supported GCC version.

Fixes #57057

llvm/include/llvm/ADT/StringRef.h

index 1f7f912..25dcda0 100644 (file)
@@ -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)