[llvm-branch-commits] [clang-tools-extra-branch] r353391 - Merging r353327:
Hans Wennborg via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Feb 7 03:04:04 PST 2019
Author: hans
Date: Thu Feb 7 03:04:04 2019
New Revision: 353391
URL: http://llvm.org/viewvc/llvm-project?rev=353391&view=rev
Log:
Merging r353327:
------------------------------------------------------------------------
r353327 | lebedevri | 2019-02-06 20:17:30 +0100 (Wed, 06 Feb 2019) | 18 lines
[clang-tidy] modernize-avoid-c-arrays: avoid main function (PR40604)
Summary:
The check should ignore the main function, the program entry point.
It is not possible to use `std::array<>` for the `argv`.
The alternative is to use `char** argv`.
Fixes [[ https://bugs.llvm.org/show_bug.cgi?id=40604 | PR40604 ]]
Reviewers: JonasToth, aaron.ballman
Reviewed By: aaron.ballman
Subscribers: xazax.hun, hans, cfe-commits
Tags: #clang-tools-extra, #clang
Differential Revision: https://reviews.llvm.org/D57787
------------------------------------------------------------------------
Added:
clang-tools-extra/branches/release_80/test/clang-tidy/modernize-avoid-c-arrays-ignores-main.cpp
- copied unchanged from r353327, clang-tools-extra/trunk/test/clang-tidy/modernize-avoid-c-arrays-ignores-main.cpp
clang-tools-extra/branches/release_80/test/clang-tidy/modernize-avoid-c-arrays-ignores-three-arg-main.cpp
- copied unchanged from r353327, clang-tools-extra/trunk/test/clang-tidy/modernize-avoid-c-arrays-ignores-three-arg-main.cpp
Modified:
clang-tools-extra/branches/release_80/ (props changed)
clang-tools-extra/branches/release_80/clang-tidy/modernize/AvoidCArraysCheck.cpp
clang-tools-extra/branches/release_80/docs/clang-tidy/checks/modernize-avoid-c-arrays.rst
Propchange: clang-tools-extra/branches/release_80/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Feb 7 03:04:04 2019
@@ -1 +1 @@
-/clang-tools-extra/trunk:351463,351466-351468,351531,351686,351738,351788,352040,352231
+/clang-tools-extra/trunk:351463,351466-351468,351531,351686,351738,351788,352040,352231,353327
Modified: clang-tools-extra/branches/release_80/clang-tidy/modernize/AvoidCArraysCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/branches/release_80/clang-tidy/modernize/AvoidCArraysCheck.cpp?rev=353391&r1=353390&r2=353391&view=diff
==============================================================================
--- clang-tools-extra/branches/release_80/clang-tidy/modernize/AvoidCArraysCheck.cpp (original)
+++ clang-tools-extra/branches/release_80/clang-tidy/modernize/AvoidCArraysCheck.cpp Thu Feb 7 03:04:04 2019
@@ -31,6 +31,12 @@ AST_MATCHER(clang::RecordDecl, isExternC
return Node.isExternCContext();
}
+AST_MATCHER(clang::ParmVarDecl, isArgvOfMain) {
+ const clang::DeclContext *DC = Node.getDeclContext();
+ const auto *FD = llvm::dyn_cast<clang::FunctionDecl>(DC);
+ return FD ? FD->isMain() : false;
+}
+
} // namespace
namespace clang {
@@ -44,7 +50,8 @@ void AvoidCArraysCheck::registerMatchers
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())))))
Modified: clang-tools-extra/branches/release_80/docs/clang-tidy/checks/modernize-avoid-c-arrays.rst
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/branches/release_80/docs/clang-tidy/checks/modernize-avoid-c-arrays.rst?rev=353391&r1=353390&r2=353391&view=diff
==============================================================================
--- clang-tools-extra/branches/release_80/docs/clang-tidy/checks/modernize-avoid-c-arrays.rst (original)
+++ clang-tools-extra/branches/release_80/docs/clang-tidy/checks/modernize-avoid-c-arrays.rst Thu Feb 7 03:04:04 2019
@@ -54,3 +54,7 @@ such headers between C code, and C++ cod
}
}
+
+Similarly, the ``main()`` function is ignored. Its second and third parameters
+can be either ``char* argv[]`` or ``char** argv``, but can not be
+``std::array<>``.
More information about the llvm-branch-commits
mailing list