Index: clang-tidy/modernize/AvoidCArraysCheck.cpp =================================================================== --- clang-tidy/modernize/AvoidCArraysCheck.cpp +++ clang-tidy/modernize/AvoidCArraysCheck.cpp @@ -30,6 +30,14 @@ return Node.isExternCContext(); } +AST_MATCHER(clang::ParmVarDecl, isArgvOfMain) { + const clang::DeclContext *DC = Node.getDeclContext(); + const clang::FunctionDecl *FD = llvm::dyn_cast(DC); + if (!FD) + return false; // If not a function, then certainly not 'main'. + return FD->isMain(); +} + } // namespace namespace clang { @@ -43,7 +51,8 @@ Finder->addMatcher( typeLoc(hasValidBeginLoc(), hasType(arrayType()), - unless(anyOf(hasParent(varDecl(isExternC())), + unless(anyOf(hasParent(parmVarDecl(isArgvOfMain())), + hasParent(varDecl(isExternC())), hasParent(fieldDecl( hasParent(recordDecl(isExternCContext())))), hasAncestor(functionDecl(isExternC()))))) Index: test/clang-tidy/modernize-avoid-c-arrays.cpp =================================================================== --- test/clang-tidy/modernize-avoid-c-arrays.cpp +++ test/clang-tidy/modernize-avoid-c-arrays.cpp @@ -86,3 +86,20 @@ int j[1]; }; } + +int not_main(int argc, char *argv[]) { + // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: do not declare C-style arrays, use std::array<> instead + int f4[] = {1, 2}; + // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use std::array<> instead +} + +int main(int argc, char *argv[]) { + int f5[] = {1, 2}; + // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use std::array<> instead + + auto not_main = [](int argc, char *argv[]) { + // CHECK-MESSAGES: :[[@LINE-1]]:32: warning: do not declare C-style arrays, use std::array<> instead + int f6[] = {1, 2}; + // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: do not declare C-style arrays, use std::array<> instead + }; +}