diff options
| author | Etienne Bergeron <etienneb@google.com> | 2016-04-04 15:46:38 +0000 |
|---|---|---|
| committer | Etienne Bergeron <etienneb@google.com> | 2016-04-04 15:46:38 +0000 |
| commit | 1eec3f01f07c88325f9958b85dee8d33f548af52 (patch) | |
| tree | 821a09582cb898b9258a18fdf5b64f4384f6ea1f /clang-tools-extra/test/clang-tidy | |
| parent | b3c2764f8966d0b9ef19938f1f3bda72eec83533 (diff) | |
| download | bcm5719-llvm-1eec3f01f07c88325f9958b85dee8d33f548af52.tar.gz bcm5719-llvm-1eec3f01f07c88325f9958b85dee8d33f548af52.zip | |
[clang-tidy] Reduce false-positive ratio in misc-suspicious-missing-comma check.
Summary:
This patch is adding detection of common string literal patterns
that should not trigger warnings.
[*] Add a limit on the number of concatenated token,
[*] Add support for parenthese sequence of tokens,
[*] Add detection of valid indentation.
As an example, this code will no longer trigger a warning:
```
const char* Array[] = {
"first literal"
"indented literal"
"indented literal",
"second literal",
[...]
```
Reviewers: alexfh
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D18695
llvm-svn: 265303
Diffstat (limited to 'clang-tools-extra/test/clang-tidy')
| -rw-r--r-- | clang-tools-extra/test/clang-tidy/misc-suspicious-missing-comma.cpp | 50 |
1 files changed, 49 insertions, 1 deletions
diff --git a/clang-tools-extra/test/clang-tidy/misc-suspicious-missing-comma.cpp b/clang-tools-extra/test/clang-tidy/misc-suspicious-missing-comma.cpp index 7b64fab45e8..0744d8f681a 100644 --- a/clang-tools-extra/test/clang-tidy/misc-suspicious-missing-comma.cpp +++ b/clang-tools-extra/test/clang-tidy/misc-suspicious-missing-comma.cpp @@ -15,7 +15,8 @@ const wchar_t* Colors[] = { L"Red", L"Yellow", L"Blue", L"Green", L"Purple", L"Rose", L"White", L"Black" }; -// The following array should not trigger any warnings. +// The following array should not trigger any warnings. There is more than 5 +// elements, but they are all concatenated string literals. const char* HttpCommands[] = { "GET / HTTP/1.0\r\n" "\r\n", @@ -26,9 +27,56 @@ const char* HttpCommands[] = { "GET /favicon.ico HTTP/1.0\r\n" "header: dummy" "\r\n", + + "GET /index.html-en HTTP/1.0\r\n" + "\r\n", + + "GET /index.html-fr HTTP/1.0\r\n" + "\r\n", + + "GET /index.html-es HTTP/1.0\r\n" + "\r\n", }; // This array is too small to trigger a warning. const char* SmallArray[] = { "a" "b", "c" }; + +// Parentheses should be enough to avoid warnings. +const char* ParentheseArray[] = { + ("a" "b"), "c", + ("d" + "e" + "f"), + "g", "h", "i", "j", "k", "l" +}; + +// Indentation should be enough to avoid warnings. +const char* CorrectlyIndentedArray[] = { + "This is a long message " + "which is spanning over multiple lines." + "And this should be fine.", + "a", "b", "c", "d", "e", "f", + "g", "h", "i", "j", "k", "l" +}; + +const char* IncorrectlyIndentedArray[] = { + "This is a long message " + "which is spanning over multiple lines." + "And this should be fine.", + "a", "b", "c", "d", "e", "f", + "g", "h", "i", "j", "k", "l" +}; +// CHECK-MESSAGES: :[[@LINE-6]]:3: warning: suspicious string literal, probably missing a comma [misc-suspicious-missing-comma] + +const char* TooManyConcatenatedTokensArray[] = { + "Dummy line", + "Dummy line", + "a" "b" "c" "d" "e" "f", + "g" "h" "i" "j" "k" "l", + "Dummy line", + "Dummy line", + "Dummy line", + "Dummy line", +}; |

