File: suspicious-missing-comma.rst

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (59 lines) | stat: -rw-r--r-- 1,500 bytes parent folder | download | duplicates (21)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
.. title:: clang-tidy - bugprone-suspicious-missing-comma

bugprone-suspicious-missing-comma
=================================

String literals placed side-by-side are concatenated at translation phase 6
(after the preprocessor). This feature is used to represent long string
literal on multiple lines.

For instance, the following declarations are equivalent:

.. code-block:: c++

  const char* A[] = "This is a test";
  const char* B[] = "This" " is a "    "test";

A common mistake done by programmers is to forget a comma between two string
literals in an array initializer list.

.. code-block:: c++

  const char* Test[] = {
    "line 1",
    "line 2"     // Missing comma!
    "line 3",
    "line 4",
    "line 5"
  };

The array contains the string "line 2line3" at offset 1 (i.e. Test[1]). Clang
won't generate warnings at compile time.

This check may warn incorrectly on cases like:

.. code-block:: c++

  const char* SupportedFormat[] = {
    "Error %s",
    "Code " PRIu64,   // May warn here.
    "Warning %s",
  };

Options
-------

.. option::  SizeThreshold

   An unsigned integer specifying the minimum size of a string literal to be
   considered by the check. Default is ``5U``.

.. option::  RatioThreshold

   A string specifying the maximum threshold ratio [0, 1.0] of suspicious string
   literals to be considered. Default is ``".2"``.

.. option::  MaxConcatenatedTokens

   An unsigned integer specifying the maximum number of concatenated tokens.
   Default is ``5U``.