Skip to content

Commit 9b80ab4

Browse files
authored
[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
1 parent 0eedc85 commit 9b80ab4

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,14 @@ void RedundantInlineSpecifierCheck::registerMatchers(MatchFinder *Finder) {
8888
this);
8989

9090
if (getLangOpts().CPlusPlus17) {
91+
const auto IsPartOfRecordDecl = hasAncestor(recordDecl());
9192
Finder->addMatcher(
92-
varDecl(isInlineSpecified(),
93-
anyOf(isInternalLinkage(StrictMode),
94-
allOf(isConstexpr(), hasAncestor(recordDecl()))))
93+
varDecl(
94+
isInlineSpecified(),
95+
anyOf(allOf(isInternalLinkage(StrictMode),
96+
unless(allOf(hasInitializer(expr()), IsPartOfRecordDecl,
97+
isStaticStorageClass()))),
98+
allOf(isConstexpr(), IsPartOfRecordDecl)))
9599
.bind("var_decl"),
96100
this);
97101
}

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@ Changes in existing checks
164164
`AllowStringArrays` option, enabling the exclusion of array types with deduced
165165
length initialized from string literals.
166166

167+
- Improved :doc:`readability-redundant-inline-specifier
168+
<clang-tidy/checks/readability/redundant-inline-specifier>` check to properly
169+
emit warnings for static data member with an in-class initializer.
170+
167171
Removed checks
168172
^^^^^^^^^^^^^^
169173

clang-tools-extra/test/clang-tidy/checkers/readability/redundant-inline-specifier.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,17 @@ INLINE_MACRO()
135135

136136
#define INLINE_KW inline
137137
INLINE_KW void fn10() { }
138+
139+
namespace {
140+
class A
141+
{
142+
public:
143+
static inline float test = 3.0F;
144+
static inline double test2 = 3.0;
145+
static inline int test3 = 3;
146+
147+
static inline float test4;
148+
// CHECK-MESSAGES-STRICT: :[[@LINE-1]]:10: warning: variable 'test4' has inline specifier but is implicitly inlined [readability-redundant-inline-specifier]
149+
// CHECK-FIXES-STRICT: static float test4;
150+
};
151+
}

0 commit comments

Comments
 (0)