[PATCH] D143971: [clang-tidy] Flag more buggy string constructor cases
Carlos Galvez via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Mar 25 04:10:50 PDT 2023
carlosgalvezp added inline comments.
================
Comment at: clang-tools-extra/docs/clang-tidy/checks/bugprone/string-constructor.rst:25
+ std::string str(buf[1], 5); // First arg should be '&buf[1]'?
+ std::string str2((int)buf[1], 5); // Ok - explicitly cast to express intent
----------------
Should we use C++ casts?
================
Comment at: clang-tools-extra/docs/clang-tidy/checks/bugprone/string-constructor.rst:25
+ std::string str(buf[1], 5); // First arg should be '&buf[1]'?
+ std::string str2((int)buf[1], 5); // Ok - explicitly cast to express intent
----------------
carlosgalvezp wrote:
> Should we use C++ casts?
Should this be a char?
================
Comment at: clang-tools-extra/test/clang-tidy/checkers/bugprone/string-constructor.cpp:141
+ std::string s4((int)kText[1], i);
+ std::string s5(kText[1], (char)i);
----------------
Shouldn't this fail, since the constructor `std::string(char, char)` does not exist?
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D143971/new/
https://reviews.llvm.org/D143971
More information about the cfe-commits
mailing list