1 .. title:: clang-tidy - bugprone-string-constructor
3 bugprone-string-constructor
4 ===========================
6 Finds string constructors that are suspicious and probably errors.
8 A common mistake is to swap parameters to the 'fill' string-constructor.
14 std::string str('x', 50); // should be str(50, 'x')
16 Calling the string-literal constructor with a length bigger than the literal is
17 suspicious and adds extra random characters to the string.
23 std::string("test", 200); // Will include random characters after "test".
24 std::string_view("test", 200);
26 Creating an empty string from constructors with parameters is considered
27 suspicious. The programmer should use the empty constructor instead.
33 std::string("test", 0); // Creation of an empty string.
34 std::string_view("test", 0);
39 .. option:: WarnOnLargeLength
41 When `true`, the check will warn on a string with a length greater than
42 :option:`LargeLengthThreshold`. Default is `true`.
44 .. option:: LargeLengthThreshold
46 An integer specifying the large length threshold. Default is `0x800000`.
48 .. option:: StringNames
50 Default is `::std::basic_string;::std::basic_string_view`.
52 Semicolon-delimited list of class names to apply this check to.
53 By default `::std::basic_string` applies to ``std::string`` and
54 ``std::wstring``. Set to e.g. `::std::basic_string;llvm::StringRef;QString`
55 to perform this check on custom classes.