[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:32:24 PST 2019


danlark updated this revision to Diff 186183.

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

https://reviews.llvm.org/D58022

Files:
  include/__string


Index: include/__string
===================================================================
--- include/__string
+++ include/__string
@@ -213,8 +213,7 @@
 
     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);}
+    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 +261,22 @@
 }
 
 inline _LIBCPP_CONSTEXPR_AFTER_CXX14
+size_t
+char_traits<char>::length(const char_type* __s) _NOEXCEPT
+{
+#if __has_feature(cxx_constexpr_string_builtins)
+    return __builtin_strlen(__s);
+#elif _LIBCPP_STD_VER <= 14
+    return 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.186183.patch
Type: text/x-patch
Size: 1244 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20190211/232d6207/attachment.bin>


More information about the libcxx-commits mailing list