[libcxx-commits] [PATCH] D58022: __builtin_strlen is not supported for MSVC e.g and it is not correct to use it without knowledge of this "builtin" in advance

Danila Kutenin via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Sun Feb 10 21:13:54 PST 2019


danlark updated this revision to Diff 186182.
danlark marked 2 inline comments as done.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D58022/new/

https://reviews.llvm.org/D58022

Files:
  __string


Index: __string
===================================================================
--- __string
+++ __string
@@ -213,8 +213,8 @@
 
     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 _LIBCPP_CONSTEXPR_AFTER_CXX14
+    size_t length(const char_type* __s) _NOEXCEPT;
     static _LIBCPP_CONSTEXPR_AFTER_CXX14
     const char_type* find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT;
     static inline char_type* move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
@@ -262,6 +262,20 @@
 }
 
 inline _LIBCPP_CONSTEXPR_AFTER_CXX14
+size_t
+char_traits<char>::length(const char_type* __s) _NOEXCEPT
+{
+#ifndef _LIBCPP_COMPILER_MSVC
+    return __builtin_strlen(__s);
+#else
+    size_t __len = 0;
+    for (; !eq(*__s, char_type(0)); ++__s)
+        ++__len;
+    return __len;
+#endif
+}
+
+inline _LIBCPP_CONSTEXPR_AFTER_CXX14
 const char*
 char_traits<char>::find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT
 {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58022.186182.patch
Type: text/x-patch
Size: 1189 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20190211/0819ebb3/attachment.bin>


More information about the libcxx-commits mailing list