[libcxx-commits] [PATCH] D115795: [libc++] Add GCC workaround in std::char_traits<char>::length()
Nikolas Klauser via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Dec 15 12:14:32 PST 2021
philnik updated this revision to Diff 394636.
philnik added a comment.
Added char_type() around '\0'
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D115795/new/
https://reviews.llvm.org/D115795
Files:
libcxx/include/__string
libcxx/test/std/strings/string.view/string.view.ops/copy.pass.cpp
Index: libcxx/test/std/strings/string.view/string.view.ops/copy.pass.cpp
===================================================================
--- libcxx/test/std/strings/string.view/string.view.ops/copy.pass.cpp
+++ libcxx/test/std/strings/string.view/string.view.ops/copy.pass.cpp
@@ -6,9 +6,6 @@
//
//===----------------------------------------------------------------------===//
-// GCC's __builtin_strlen isn't constexpr yet
-// XFAIL: gcc-11 && !(c++11 || c++14 || c++17)
-
// <string_view>
// size_type copy(charT* s, size_type n, size_type pos = 0) const;
Index: libcxx/include/__string
===================================================================
--- libcxx/include/__string
+++ libcxx/include/__string
@@ -337,8 +337,21 @@
static _LIBCPP_CONSTEXPR_AFTER_CXX14
int compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT;
- static inline size_t _LIBCPP_CONSTEXPR_AFTER_CXX14
- length(const char_type* __s) _NOEXCEPT {return __builtin_strlen(__s);}
+
+ static inline size_t _LIBCPP_CONSTEXPR_AFTER_CXX14 length(const char_type* __s) _NOEXCEPT {
+ // GCC currently does not support __builtin_strlen during constant evaluation.
+ // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70816
+#ifdef _LIBCPP_COMPILER_GCC
+ if (__libcpp_is_constant_evaluated()) {
+ size_t __i = 0;
+ for (; __s[__i] != char_type('\0'); ++__i)
+ ;
+ return __i;
+ }
+#endif
+ return __builtin_strlen(__s);
+ }
+
static _LIBCPP_CONSTEXPR_AFTER_CXX14
const char_type* find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT;
static inline _LIBCPP_CONSTEXPR_AFTER_CXX17
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115795.394636.patch
Type: text/x-patch
Size: 1693 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20211215/dcfbbff9/attachment.bin>
More information about the libcxx-commits
mailing list