diff options
author | Gabor Horvath <xazax.hun@gmail.com> | 2015-12-15 08:47:20 +0000 |
---|---|---|
committer | Gabor Horvath <xazax.hun@gmail.com> | 2015-12-15 08:47:20 +0000 |
commit | 454564a2d940e28577ef110474b026c568e60f46 (patch) | |
tree | ce5e40ba1ac16818229d4ad181522d156e6d9951 /clang-tools-extra/docs/clang-tidy | |
parent | 6015f5c8237c259ac04c539d55d200baa885a807 (diff) | |
download | bcm5719-llvm-454564a2d940e28577ef110474b026c568e60f46.tar.gz bcm5719-llvm-454564a2d940e28577ef110474b026c568e60f46.zip |
[clang-tidy] Check for suspicious string assignments.
It is possible to assign arbitrary integer types to strings.
Sometimes it is the result of missing to_string call or apostrophes.
Reviewers: alexfh
Differential Revision: http://reviews.llvm.org/D15411
llvm-svn: 255630
Diffstat (limited to 'clang-tools-extra/docs/clang-tidy')
-rw-r--r-- | clang-tools-extra/docs/clang-tidy/checks/list.rst | 1 | ||||
-rw-r--r-- | clang-tools-extra/docs/clang-tidy/checks/misc-string-integer-assignment.rst | 31 |
2 files changed, 32 insertions, 0 deletions
diff --git a/clang-tools-extra/docs/clang-tidy/checks/list.rst b/clang-tools-extra/docs/clang-tidy/checks/list.rst index 2f1686fa995..f8001440e73 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/list.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/list.rst @@ -48,6 +48,7 @@ List of clang-tidy Checks misc-non-copyable-objects misc-sizeof-container misc-static-assert + misc-string-integer-assignment misc-swapped-arguments misc-throw-by-value-catch-by-reference misc-undelegated-constructor diff --git a/clang-tools-extra/docs/clang-tidy/checks/misc-string-integer-assignment.rst b/clang-tools-extra/docs/clang-tidy/checks/misc-string-integer-assignment.rst new file mode 100644 index 00000000000..4e2aeef2183 --- /dev/null +++ b/clang-tools-extra/docs/clang-tidy/checks/misc-string-integer-assignment.rst @@ -0,0 +1,31 @@ +misc-string-integer-assignment +============================== + +The check finds assignments of an integer to ``std::basic_string<CharT>`` +(``std::string``, ``std::wstring``, etc.). The source of the problem is the +following assignment operator of ``std::basic_string<CharT>``: + +.. code:: c++ + basic_string& operator=( CharT ch ); + +Numeric types can be implicity casted to character types. + +.. code:: c++ + std::string s; + int x = 5965; + s = 6; + s = x; + +Use the appropriate conversion functions or character literals. + +.. code:: c++ + std::string s; + int x = 5965; + s = '6'; + s = std::to_string(x); + +In order to suppress false positives, use an explicit cast. + +.. code:: c++ + std::string s; + s = static_cast<char>(6); |