[libcxx-commits] [PATCH] D115795: [libc++] Add GCC workaround for std::char_traits<char>::length()
Nikolas Klauser via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Dec 15 04:14:35 PST 2021
philnik created this revision.
philnik added reviewers: Quuxplusone, ldionne.
philnik requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.
Add GCC workarount for `std::char_traits<char>::length()`
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D115795
Files:
libcxx/include/__string
Index: libcxx/include/__string
===================================================================
--- libcxx/include/__string
+++ libcxx/include/__string
@@ -337,8 +337,20 @@
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 {
+#ifdef _LIBCPP_COMPILER_GCC
+ if (__libcpp_is_constant_evaluated()) {
+ size_t __i = 0;
+ for (; __s[i] != '\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.394525.patch
Type: text/x-patch
Size: 951 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20211215/8f9fb264/attachment-0001.bin>
More information about the libcxx-commits
mailing list