[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 20:37:05 PST 2019


danlark created this revision.
danlark added reviewers: mclow.lists, EricWF.
Herald added a subscriber: ldionne.

There is no analogue of constexpr __builtin_strlen for MSVC, so make it through defines as it was done for `char_traits<wchar_t>`


Repository:
  rCXX libc++

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,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.186180.patch
Type: text/x-patch
Size: 1262 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20190211/dc3a83d4/attachment.bin>


More information about the libcxx-commits mailing list