Skip to content

Commit b4c4573

Browse files
committed
Explicitly exclude function arguments
1 parent 050d53b commit b4c4573

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

clang-tools-extra/clang-tidy/modernize/AvoidCArraysCheck.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,8 @@ void AvoidCArraysCheck::registerMatchers(MatchFinder *Finder) {
5353
anything();
5454
if (AllowStringArrays)
5555
IgnoreStringArrayIfNeededMatcher =
56-
unless(typeLoc(loc(hasCanonicalType(incompleteArrayType(
57-
hasElementType(isAnyCharacter())))),
58-
hasParent(varDecl(hasInitializer(stringLiteral())))));
56+
unless(typeLoc(loc(hasCanonicalType(incompleteArrayType(hasElementType(isAnyCharacter())))),
57+
hasParent(varDecl(hasInitializer(stringLiteral()), unless(parmVarDecl())))));
5958

6059
Finder->addMatcher(
6160
typeLoc(hasValidBeginLoc(), hasType(arrayType()),

clang-tools-extra/test/clang-tidy/checkers/modernize/avoid-c-arrays-ignores-strings.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@
44
const char name[] = "name";
55
const char array[] = {'n', 'a', 'm', 'e', '\0'};
66
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: do not declare C-style arrays, use std::array<> instead [modernize-avoid-c-arrays]
7+
8+
void takeCharArray(const char name[]);
9+
// CHECK-MESSAGES: :[[@LINE-1]]:26: warning: do not declare C-style arrays, use std::array<> instead [modernize-avoid-c-arrays]

clang-tools-extra/test/clang-tidy/checkers/modernize/avoid-c-arrays.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,6 @@ struct Bar {
8989

9090
const char name[] = "Some string";
9191
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: do not declare C-style arrays, use std::array<> instead [modernize-avoid-c-arrays]
92+
93+
void takeCharArray(const char name[]);
94+
// CHECK-MESSAGES: :[[@LINE-1]]:26: warning: do not declare C-style arrays, use std::array<> instead [modernize-avoid-c-arrays]

0 commit comments

Comments
 (0)