[llvm] [ADT] Fix llvm::join on containers of char*s (PR #67113)

Sam McCall via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 27 11:18:24 PDT 2023


================
@@ -417,8 +418,13 @@ inline std::string join_impl(IteratorT Begin, IteratorT End,
     return S;
 
   size_t Len = (std::distance(Begin, End) - 1) * Separator.size();
-  for (IteratorT I = Begin; I != End; ++I)
-    Len += (*I).size();
+  for (IteratorT I = Begin; I != End; ++I) {
+    if constexpr (std::is_same_v<std::remove_reference_t<decltype(*I)>,
+                                 const char *>)
+      Len += strlen(*I);
+    else
+      Len += (*I).size();
----------------
sam-mccall wrote:

oh of course, *always* use stringref. thanks!

https://github.com/llvm/llvm-project/pull/67113


More information about the llvm-commits mailing list