38 lines · plain
1.. title:: clang-tidy - bugprone-string-integer-assignment2 3bugprone-string-integer-assignment4==================================5 6The check finds assignments of an integer to ``std::basic_string<CharT>``7(``std::string``, ``std::wstring``, etc.). The source of the problem is the8following assignment operator of ``std::basic_string<CharT>``:9 10.. code-block:: c++11 12 basic_string& operator=( CharT ch );13 14Numeric types can be implicitly casted to character types.15 16.. code-block:: c++17 18 std::string s;19 int x = 5965;20 s = 6;21 s = x;22 23Use the appropriate conversion functions or character literals.24 25.. code-block:: c++26 27 std::string s;28 int x = 5965;29 s = '6';30 s = std::to_string(x);31 32In order to suppress false positives, use an explicit cast.33 34.. code-block:: c++35 36 std::string s;37 s = static_cast<char>(6);38