[libcxx-commits] [libcxx] 96f1cd2 - [libc++][test] Silence MSVC warning

Casey Carter via libcxx-commits libcxx-commits at lists.llvm.org
Mon Jan 9 15:05:45 PST 2023


Author: Casey Carter
Date: 2023-01-09T15:05:31-08:00
New Revision: 96f1cd2427e472acf65e1b0b755a2c1f672e730b

URL: https://github.com/llvm/llvm-project/commit/96f1cd2427e472acf65e1b0b755a2c1f672e730b
DIFF: https://github.com/llvm/llvm-project/commit/96f1cd2427e472acf65e1b0b755a2c1f672e730b.diff

LOG: [libc++][test] Silence MSVC warning

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.

Differential Revision: https://reviews.llvm.org/D141263

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/libcxx/test/std/ranges/range.factories/range.istream.view/utils.h b/libcxx/test/std/ranges/range.factories/range.istream.view/utils.h
index ec6ed4daf37c2..254c95b51acb9 100644
--- a/libcxx/test/std/ranges/range.factories/range.istream.view/utils.h
+++ b/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>


        


More information about the libcxx-commits mailing list