[PATCH] D19146: [clang-tidy] New checker to detect suspicious string constructor.

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 15 05:38:39 PDT 2016


On Thu, Apr 14, 2016 at 11:29 PM, Etienne Bergeron via cfe-commits
<cfe-commits at lists.llvm.org> wrote:
> etienneb created this revision.
> etienneb added a reviewer: alexfh.
> etienneb added a subscriber: cfe-commits.
>
> Checker to validate string constructor parameters.
>
> A common mistake is to swap parameter for the fill-constructor.
> ```
>   std::string str('x', 4);
>   std::string str('4', x);
> ```

Could this check be generalized to any function call expression
(including constructor calls, etc)? It seems to me that this pattern
is "one param is a char and an adjacent param is an integral type
other than char" that are conflated between the declaration and the
call, but in some regards, I kind of wonder if this could even be
applied to any two types that have an implicit conversion path between
them.

~Aaron

>
> http://reviews.llvm.org/D19146
>
> Files:
>   clang-tidy/misc/CMakeLists.txt
>   clang-tidy/misc/MiscTidyModule.cpp
>   clang-tidy/misc/StringConstructorCheck.cpp
>   clang-tidy/misc/StringConstructorCheck.h
>   docs/clang-tidy/checks/list.rst
>   docs/clang-tidy/checks/misc-string-constructor.rst
>   test/clang-tidy/misc-string-constructor.cpp
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>


More information about the cfe-commits mailing list