brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.9 KiB · ad4ed89 Raw
68 lines · plain
1.. title:: clang-tidy - bugprone-string-constructor2 3bugprone-string-constructor4===========================5 6Finds string constructors that are suspicious and probably errors.7 8A common mistake is to swap parameters to the 'fill' string-constructor.9 10Examples:11 12.. code-block:: c++13 14  std::string str('x', 50); // should be str(50, 'x')15 16Calling the string-literal constructor with a length bigger than the literal is17suspicious and adds extra random characters to the string.18 19Examples:20 21.. code-block:: c++22 23  std::string("test", 200);   // Will include random characters after "test".24  std::string("test", 2, 5);  // Will include random characters after "st".25  std::string_view("test", 200);26 27Creating an empty string from constructors with parameters is considered28suspicious. The programmer should use the empty constructor instead.29 30Examples:31 32.. code-block:: c++33 34  std::string("test", 0);   // Creation of an empty string.35  std::string("test", 1, 0);36  std::string_view("test", 0);37 38Passing an invalid first character position parameter to constructor will39cause ``std::out_of_range`` exception at runtime.40 41Examples:42 43.. code-block:: c++44 45  std::string("test", -1, 10); // Negative first character position.46  std::string("test", 10, 10); // First character position is bigger than string literal character range".47 48Options49-------50 51.. option::  WarnOnLargeLength52 53   When `true`, the check will warn on a string with a length greater than54   :option:`LargeLengthThreshold`. Default is `true`.55 56.. option::  LargeLengthThreshold57 58   An integer specifying the large length threshold. Default is `0x800000`.59 60.. option:: StringNames61 62    Default is `::std::basic_string;::std::basic_string_view`.63 64    Semicolon-delimited list of class names to apply this check to.65    By default `::std::basic_string` applies to ``std::string`` and66    ``std::wstring``. Set to e.g. `::std::basic_string;llvm::StringRef;QString`67    to perform this check on custom classes.68