https://github.com/felix642 updated https://github.com/llvm/llvm-project/pull/81423
From 0fa56a4176205337270d15049dc34a8508488905 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix-Antoine=20Constantin?= <felix-antoine.constan...@bidgroup.ca> Date: Thu, 8 Feb 2024 17:07:38 -0500 Subject: [PATCH 1/2] =?UTF-8?q?[clang-tidy]=C2=A0Removed=20redundant-inlin?= =?UTF-8?q?e-specifier=20warning=20on=20static=20data=20members?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updated the check to ignore point static data members with in class initializer since removing the inline specifier would generate a compilation error Fixes #80684 --- .../RedundantInlineSpecifierCheck.cpp | 17 +++++++++++------ clang-tools-extra/docs/ReleaseNotes.rst | 4 ++++ .../readability/redundant-inline-specifier.cpp | 14 ++++++++++++++ 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp b/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp index 0e8d17d4442478..3d6b052686c20c 100644 --- a/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp @@ -47,6 +47,9 @@ AST_POLYMORPHIC_MATCHER_P(isInternalLinkage, return VD->isInAnonymousNamespace(); llvm_unreachable("Not a valid polymorphic type"); } + +AST_MATCHER(clang::VarDecl, hasInitialization) { return Node.hasInit(); } + } // namespace static SourceLocation getInlineTokenLocation(SourceRange RangeLocation, @@ -88,12 +91,14 @@ void RedundantInlineSpecifierCheck::registerMatchers(MatchFinder *Finder) { this); if (getLangOpts().CPlusPlus17) { - Finder->addMatcher( - varDecl(isInlineSpecified(), - anyOf(isInternalLinkage(StrictMode), - allOf(isConstexpr(), hasAncestor(recordDecl())))) - .bind("var_decl"), - this); + const auto IsPartOfRecordDecl = hasAncestor(recordDecl()); + Finder->addMatcher(varDecl(isInlineSpecified(), + anyOf(allOf(isInternalLinkage(StrictMode), + unless(allOf(hasInitialization(), + IsPartOfRecordDecl))), + allOf(isConstexpr(), IsPartOfRecordDecl))) + .bind("var_decl"), + this); } } diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index ee68c8f49b3df2..303bfef17015a0 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -160,6 +160,10 @@ Changes in existing checks `AllowStringArrays` option, enabling the exclusion of array types with deduced length initialized from string literals. +- Improved :doc:`readability-redundant-inline-specifier + <clang-tidy/checks/readability/redundant-inline-specifier>` check to properly + emit warnings for static data member with an in-class initializer. + Removed checks ^^^^^^^^^^^^^^ diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-inline-specifier.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-inline-specifier.cpp index cdd98d8fdc20f5..14f9e88f7e7218 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-inline-specifier.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-inline-specifier.cpp @@ -135,3 +135,17 @@ INLINE_MACRO() #define INLINE_KW inline INLINE_KW void fn10() { } + +namespace { +class A +{ +public: + static inline float test = 3.0F; + static inline double test2 = 3.0; + static inline int test3 = 3; + + static inline float test4; + // CHECK-MESSAGES-STRICT: :[[@LINE-1]]:10: warning: variable 'test4' has inline specifier but is implicitly inlined [readability-redundant-inline-specifier] + // CHECK-FIXES-STRICT: static float test4; +}; +} From 3b4684a3003793e80d25e8a75c8252dbb5514cea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix-Antoine=20Constantin?= <felix-antoine.constan...@polymtl.ca> Date: Sun, 11 Feb 2024 21:02:59 -0500 Subject: [PATCH 2/2] =?UTF-8?q?fixup!=20[clang-tidy]=C2=A0Removed=20redund?= =?UTF-8?q?ant-inline-specifier=20warning=20on=20static=20data=20members?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Improved AST Matcher based on comments --- .../RedundantInlineSpecifierCheck.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp b/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp index 3d6b052686c20c..1693e5c5e9cd45 100644 --- a/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp @@ -47,9 +47,6 @@ AST_POLYMORPHIC_MATCHER_P(isInternalLinkage, return VD->isInAnonymousNamespace(); llvm_unreachable("Not a valid polymorphic type"); } - -AST_MATCHER(clang::VarDecl, hasInitialization) { return Node.hasInit(); } - } // namespace static SourceLocation getInlineTokenLocation(SourceRange RangeLocation, @@ -92,13 +89,15 @@ void RedundantInlineSpecifierCheck::registerMatchers(MatchFinder *Finder) { if (getLangOpts().CPlusPlus17) { const auto IsPartOfRecordDecl = hasAncestor(recordDecl()); - Finder->addMatcher(varDecl(isInlineSpecified(), - anyOf(allOf(isInternalLinkage(StrictMode), - unless(allOf(hasInitialization(), - IsPartOfRecordDecl))), - allOf(isConstexpr(), IsPartOfRecordDecl))) - .bind("var_decl"), - this); + Finder->addMatcher( + varDecl( + isInlineSpecified(), + anyOf(allOf(isInternalLinkage(StrictMode), + unless(allOf(hasInitializer(expr()), IsPartOfRecordDecl, + isStaticStorageClass()))), + allOf(isConstexpr(), IsPartOfRecordDecl))) + .bind("var_decl"), + this); } } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits