summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFélix-Antoine Constantin <60141446+felix642@users.noreply.github.com>2024-02-14 14:30:21 -0500
committerGitHub <noreply@github.com>2024-02-14 20:30:21 +0100
commit9b80ab4332bbe336ab8b9f2082eadf6b8d223150 (patch)
treeaa82ff32d8cce01b4e2e2a25a4d8657a00d2aa9b
parent0eedc85baad495fa916d1da7b20db93a29b443e1 (diff)
[clang-tidy] Removed redundant-inline-specifier warning on static data members (#81423)
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
-rw-r--r--clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp10
-rw-r--r--clang-tools-extra/docs/ReleaseNotes.rst4
-rw-r--r--clang-tools-extra/test/clang-tidy/checkers/readability/redundant-inline-specifier.cpp14
3 files changed, 25 insertions, 3 deletions
diff --git a/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp b/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp
index 0e8d17d44424..1693e5c5e9cd 100644
--- a/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp
@@ -88,10 +88,14 @@ void RedundantInlineSpecifierCheck::registerMatchers(MatchFinder *Finder) {
this);
if (getLangOpts().CPlusPlus17) {
+ const auto IsPartOfRecordDecl = hasAncestor(recordDecl());
Finder->addMatcher(
- varDecl(isInlineSpecified(),
- anyOf(isInternalLinkage(StrictMode),
- allOf(isConstexpr(), hasAncestor(recordDecl()))))
+ varDecl(
+ isInlineSpecified(),
+ anyOf(allOf(isInternalLinkage(StrictMode),
+ unless(allOf(hasInitializer(expr()), IsPartOfRecordDecl,
+ isStaticStorageClass()))),
+ allOf(isConstexpr(), IsPartOfRecordDecl)))
.bind("var_decl"),
this);
}
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index f2fba9aa1450..2f874d17da43 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -164,6 +164,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 cdd98d8fdc20..14f9e88f7e72 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;
+};
+}