27 lines · plain
1.. title:: clang-tidy - bugprone-sizeof-container2 3bugprone-sizeof-container4=========================5 6The check finds usages of ``sizeof`` on expressions of STL container types.7Most likely the user wanted to use ``.size()`` instead.8 9All class/struct types declared in namespace ``std::`` having a const10``size()`` method are considered containers, with the exception of11``std::bitset`` and ``std::array``.12 13Examples:14 15.. code-block:: c++16 17 std::string s;18 int a = 47 + sizeof(s); // warning: sizeof() doesn't return the size of the container. Did you mean .size()?19 20 int b = sizeof(std::string); // no warning, probably intended.21 22 std::string array_of_strings[10];23 int c = sizeof(array_of_strings) / sizeof(array_of_strings[0]); // no warning, definitely intended.24 25 std::array<int, 3> std_array;26 int d = sizeof(std_array); // no warning, probably intended.27