[clang-tools-extra] Add new check: do not return 0; at the end of main() in C++ (PR #77586)

via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 10 03:27:33 PST 2024


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff 8f78dd4b92b44c490d263a4d161850853874859d bae95013cd7f937a5496cafcd40a77cc563addb0 -- clang-tools-extra/clang-tidy/readability/DonotreturnzerocheckCheck.cpp clang-tools-extra/clang-tidy/readability/DonotreturnzerocheckCheck.h clang-tools-extra/test/clang-tidy/checkers/readability/DoNotReturnZeroCheck.cpp clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/clang-tools-extra/clang-tidy/readability/DonotreturnzerocheckCheck.cpp b/clang-tools-extra/clang-tidy/readability/DonotreturnzerocheckCheck.cpp
index 66ea29be3c..4a741940bf 100644
--- a/clang-tools-extra/clang-tidy/readability/DonotreturnzerocheckCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/DonotreturnzerocheckCheck.cpp
@@ -12,24 +12,21 @@
 
 using namespace clang::ast_matchers;
 
-
-
 namespace clang::tidy::readability {
-  bool isCPlusPlusOrC99(const LangOptions &LangOpts) {
+bool isCPlusPlusOrC99(const LangOptions &LangOpts) {
   return LangOpts.CPlusPlus || LangOpts.C99;
-  }
+}
 
 void DonotreturnzerocheckCheck::registerMatchers(MatchFinder *Finder) {
   // FIXME: Add matchers.
-  Finder->addMatcher(functionDecl(
-    isMain(),returns(asString("int"))
-  ).bind("main"), this);
+  Finder->addMatcher(
+      functionDecl(isMain(), returns(asString("int"))).bind("main"), this);
 }
 
 void DonotreturnzerocheckCheck::check(const MatchFinder::MatchResult &Result) {
   // FIXME: Add callback implementation.
   const auto *MatchedDecl = Result.Nodes.getNodeAs<FunctionDecl>("main");
-  if(isCPlusPlusOrC99(Result.Context->getLangOpts())){
+  if (isCPlusPlusOrC99(Result.Context->getLangOpts())) {
     SourceLocation ReturnLoc;
     if (MatchedDecl->hasBody()) {
       const CompoundStmt *Body = dyn_cast<CompoundStmt>(MatchedDecl->getBody());
@@ -44,11 +41,10 @@ void DonotreturnzerocheckCheck::check(const MatchFinder::MatchResult &Result) {
     if (ReturnLoc.isValid()) {
       // Suggest removal of the redundant return statement.
       diag(ReturnLoc, "redundant 'return 0;' at the end of main")
-          << FixItHint::CreateRemoval(CharSourceRange::getTokenRange(ReturnLoc));
+          << FixItHint::CreateRemoval(
+                 CharSourceRange::getTokenRange(ReturnLoc));
     }
-
   }
-
 }
 
-}
\ No newline at end of file
+} // namespace clang::tidy::readability
\ No newline at end of file

``````````

</details>


https://github.com/llvm/llvm-project/pull/77586


More information about the cfe-commits mailing list