Index: clang/docs/LibASTMatchersReference.html =================================================================== --- clang/docs/LibASTMatchersReference.html +++ clang/docs/LibASTMatchersReference.html @@ -2919,6 +2919,12 @@ +Matcher<FunctionDecl>isMain +
Determines whether the function is "main", which is the entry point
+into an executable program.
+
+ + Matcher<FunctionDecl>isNoReturn
Matches FunctionDecls that have a noreturn attribute.
 
@@ -3275,9 +3281,9 @@
 matcher = objcMessagaeExpr(isInstanceMessage())
 matches
   NSString *x = @"hello";
-  [x containsString:@"h"]
+  [x containsString:@"h"];
 but not
-  [NSString stringWithFormat:@"format"]
+  [NSString stringWithFormat:@"format"];
 
@@ -5894,7 +5900,7 @@ For example the method call in NSString *x = @"hello"; - [x containsString:@"h"] + [x containsString:@"h"]; is matched by objcMessageExpr(hasReceiver(declRefExpr(to(varDecl(hasName("x")))))) @@ -6564,7 +6570,7 @@ For example, in: class A {}; using B = A; -The matcher type(hasUnqualifeidDesugaredType(recordType())) matches +The matcher type(hasUnqualifiedDesugaredType(recordType())) matches both B and A. Index: clang/include/clang/ASTMatchers/ASTMatchers.h =================================================================== --- clang/include/clang/ASTMatchers/ASTMatchers.h +++ clang/include/clang/ASTMatchers/ASTMatchers.h @@ -616,6 +616,12 @@ InnerMatcher.matches(*Initializer, Finder, Builder)); } +/// Determines whether the function is "main", which is the entry point +/// into an executable program. +AST_MATCHER(FunctionDecl, isMain) { + return Node.isMain(); +} + /// Matches the specialized template of a specialization declaration. /// /// Given Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp =================================================================== --- clang/lib/ASTMatchers/Dynamic/Registry.cpp +++ clang/lib/ASTMatchers/Dynamic/Registry.cpp @@ -358,6 +358,7 @@ REGISTER_MATCHER(isInTemplateInstantiation); REGISTER_MATCHER(isLambda); REGISTER_MATCHER(isListInitialization); + REGISTER_MATCHER(isMain); REGISTER_MATCHER(isMemberInitializer); REGISTER_MATCHER(isMoveAssignmentOperator); REGISTER_MATCHER(isMoveConstructor); Index: clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp =================================================================== --- clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp +++ clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp @@ -2158,5 +2158,13 @@ notMatches("void x() { int a; if(a == 0) return; }", BinAsgmtOperator)); } +TEST(Matcher, isMain) { + EXPECT_TRUE( + matches("int main() {}", functionDecl(isMain()))); + + EXPECT_TRUE( + notMatches("int main2() {}", functionDecl(isMain()))); +} + } // namespace ast_matchers } // namespace clang