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
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>