xref: /llvm-project/clang-tools-extra/docs/clang-tidy/checks/bugprone/suspicious-missing-comma.rst (revision 6e566bc5523f743bc34a7e26f050f1f2b4d699a8)
1.. title:: clang-tidy - bugprone-suspicious-missing-comma
2
3bugprone-suspicious-missing-comma
4=================================
5
6String literals placed side-by-side are concatenated at translation phase 6
7(after the preprocessor). This feature is used to represent long string
8literal on multiple lines.
9
10For instance, the following declarations are equivalent:
11
12.. code-block:: c++
13
14  const char* A[] = "This is a test";
15  const char* B[] = "This" " is a "    "test";
16
17A common mistake done by programmers is to forget a comma between two string
18literals in an array initializer list.
19
20.. code-block:: c++
21
22  const char* Test[] = {
23    "line 1",
24    "line 2"     // Missing comma!
25    "line 3",
26    "line 4",
27    "line 5"
28  };
29
30The array contains the string "line 2line3" at offset 1 (i.e. Test[1]). Clang
31won't generate warnings at compile time.
32
33This check may warn incorrectly on cases like:
34
35.. code-block:: c++
36
37  const char* SupportedFormat[] = {
38    "Error %s",
39    "Code " PRIu64,   // May warn here.
40    "Warning %s",
41  };
42
43Options
44-------
45
46.. option::  SizeThreshold
47
48   An unsigned integer specifying the minimum size of a string literal to be
49   considered by the check. Default is ``5U``.
50
51.. option::  RatioThreshold
52
53   A string specifying the maximum threshold ratio [0, 1.0] of suspicious string
54   literals to be considered. Default is ``".2"``.
55
56.. option::  MaxConcatenatedTokens
57
58   An unsigned integer specifying the maximum number of concatenated tokens.
59   Default is ``5U``.
60