diff options
author | Etienne Bergeron <etienneb@google.com> | 2016-03-31 18:12:23 +0000 |
---|---|---|
committer | Etienne Bergeron <etienneb@google.com> | 2016-03-31 18:12:23 +0000 |
commit | 3e4adf17625595d9425fb8109126af22475f54c0 (patch) | |
tree | 6f56b1b5347bb7ffadff6b59fc0371e29ad42ed2 /clang-tools-extra/docs/clang-tidy | |
parent | 4badd6aaf30859ce9b89960d8cae2b9ecd1dacca (diff) | |
download | bcm5719-llvm-3e4adf17625595d9425fb8109126af22475f54c0.tar.gz bcm5719-llvm-3e4adf17625595d9425fb8109126af22475f54c0.zip |
[clang-tidy] Add a new checker to detect missing comma in initializer list.
Summary:
This checker is able to detect missing comma in
an array of string literals.
```
const char* A[] = {
"abc",
"def" // missing comma (no compiler warnings)
"ghi",
};
```
The ratio of false-positive is reduced by restricting the
size of the array considered and the ratio of missing
comma.
To validate the quantity of false positive, the checker
was tried over LLVM and chromium code and detected these
cases:
[[ http://reviews.llvm.org/D18454 | http://reviews.llvm.org/D18454 ]]
[[https://codereview.chromium.org/1807753002/ | https://codereview.chromium.org/1807753002/]]
[[https://codereview.chromium.org/1826193002/ | https://codereview.chromium.org/1826193002/]]
[[https://codereview.chromium.org/1805713002/ | https://codereview.chromium.org/1805713002/]]
Reviewers: alexfh
Subscribers: LegalizeAdulthood, szdominik, xazax.hun, cfe-commits
Differential Revision: http://reviews.llvm.org/D18457
llvm-svn: 265033
Diffstat (limited to 'clang-tools-extra/docs/clang-tidy')
-rw-r--r-- | clang-tools-extra/docs/clang-tidy/checks/list.rst | 1 | ||||
-rw-r--r-- | clang-tools-extra/docs/clang-tidy/checks/misc-suspicious-missing-comma.rst | 35 |
2 files changed, 36 insertions, 0 deletions
diff --git a/clang-tools-extra/docs/clang-tidy/checks/list.rst b/clang-tools-extra/docs/clang-tidy/checks/list.rst index 912b04ae6f3..c80ea50f072 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/list.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/list.rst @@ -66,6 +66,7 @@ Clang-Tidy Checks misc-sizeof-container misc-static-assert misc-string-integer-assignment + misc-suspicious-missing-comma misc-suspicious-semicolon misc-swapped-arguments misc-throw-by-value-catch-by-reference diff --git a/clang-tools-extra/docs/clang-tidy/checks/misc-suspicious-missing-comma.rst b/clang-tools-extra/docs/clang-tidy/checks/misc-suspicious-missing-comma.rst new file mode 100644 index 00000000000..e46566a3491 --- /dev/null +++ b/clang-tools-extra/docs/clang-tidy/checks/misc-suspicious-missing-comma.rst @@ -0,0 +1,35 @@ +.. title:: clang-tidy - misc-suspicious-missing-comma + +misc-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, these declarations are equivalent: + 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. + + 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 checker may warn incorrectly on cases like: + + const char* SupportedFormat[] = { + "Error %s", + "Code " PRIu64, // May warn here. + "Warning %s", + }; |