[clang-tools-extra] eb03fa1 - [clang-tidy] Don't suggest "inline" fix for main function in
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 20 05:24:51 PDT 2021
Author: Haojian Wu
Date: 2021-07-20T14:24:38+02:00
New Revision: eb03fa1d2c05bad5a5f75a89d47b4b31d84bb90b
URL: https://github.com/llvm/llvm-project/commit/eb03fa1d2c05bad5a5f75a89d47b4b31d84bb90b
DIFF: https://github.com/llvm/llvm-project/commit/eb03fa1d2c05bad5a5f75a89d47b4b31d84bb90b.diff
LOG: [clang-tidy] Don't suggest "inline" fix for main function in
definitions-in-headers check.
Added:
Modified:
clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
clang-tools-extra/test/clang-tidy/checkers/misc-definitions-in-headers.hpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp b/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
index 820bb3bebd913..882d254c6d9ea 100644
--- a/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
@@ -127,6 +127,9 @@ void DefinitionsInHeadersCheck::check(const MatchFinder::MatchResult &Result) {
"in a header file; function definitions in header files can lead to "
"ODR violations")
<< IsFullSpec << FD;
+ // inline is not allowed for main function.
+ if (FD->isMain())
+ return;
diag(FD->getLocation(), /*FixDescription=*/"make as 'inline'",
DiagnosticIDs::Note)
<< FixItHint::CreateInsertion(FD->getInnerLocStart(), "inline ");
diff --git a/clang-tools-extra/test/clang-tidy/checkers/misc-definitions-in-headers.hpp b/clang-tools-extra/test/clang-tidy/checkers/misc-definitions-in-headers.hpp
index 7b017391d5acb..c2a4a81ae3e16 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/misc-definitions-in-headers.hpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc-definitions-in-headers.hpp
@@ -192,3 +192,7 @@ template <>
const int f12() { return 0; }
// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: full function template specialization 'f12<int>' defined in a header file;
// CHECK-FIXES: inline const int f12() { return 0; }
+
+int main() {}
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'main' defined in a header file;
+// CHECK-FIXES: {{^}}int main() {
More information about the cfe-commits
mailing list