[libcxx-commits] [PATCH] D141263: [libc++][test] Silence MSVC warning

Casey Carter via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Jan 9 01:36:52 PST 2023


CaseyCarter created this revision.
CaseyCarter added a reviewer: huixie90.
CaseyCarter added a project: libc++.
Herald added a project: All.
CaseyCarter requested review of this revision.
Herald added a reviewer: libc++.

Our static analyzer likes to warn when loop bodies are never executed, which is true for `make_string<T>("")`. Build the result with `basic_string`'s iterator-pair constructor instead, which is simpler (one liner), faster (single pass), and doesn't trigger the warning.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141263

Files:
  libcxx/test/std/ranges/range.factories/range.istream.view/utils.h


Index: libcxx/test/std/ranges/range.factories/range.istream.view/utils.h
===================================================================
--- libcxx/test/std/ranges/range.factories/range.istream.view/utils.h
+++ libcxx/test/std/ranges/range.factories/range.istream.view/utils.h
@@ -6,11 +6,7 @@
 
 template <class CharT, std::size_t N>
 auto make_string(const char (&in)[N]) {
-  std::basic_string<CharT> r(N - 1, static_cast<CharT>(0));
-  for (std::size_t i = 0; i < N - 1; ++i) {
-    r[i] = static_cast<CharT>(in[i]);
-  }
-  return r;
+  return std::basic_string<CharT>(in + 0, in + (N - 1));
 }
 
 template <class CharT, std::size_t N>


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D141263.487334.patch
Type: text/x-patch
Size: 645 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20230109/ff9590b7/attachment.bin>


More information about the libcxx-commits mailing list