Skip to content

Commit fe1a9be

Browse files
committed
fixup! [clang-tidy] Added check to detect redundant inline keyword
Fixed a few more issues - default methods should now trigger the warning - functions and variables in anonymous namespace should also trigger this warning
1 parent e61587e commit fe1a9be

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,14 @@ getInlineTokenLocation(SourceRange RangeLocation, const SourceManager &Sources,
5555

5656
void RedundantInlineSpecifierCheck::registerMatchers(MatchFinder *Finder) {
5757
Finder->addMatcher(
58-
functionDecl(unless(isExpansionInSystemHeader()), isInlineSpecified(),
59-
anyOf(isConstexpr(), isDeleted(),
58+
functionDecl(isInlineSpecified(), anyOf(isConstexpr(), isDeleted(), isDefaulted(), isInAnonymousNamespace(),
6059
allOf(isDefinition(), hasAncestor(recordDecl()))))
6160
.bind("fun_decl"),
6261
this);
6362

6463
Finder->addMatcher(
6564
varDecl(isInlineSpecified(),
66-
anyOf(allOf(isConstexpr(), unless(isStaticStorageClass())),
67-
hasAncestor(recordDecl())))
65+
anyOf(isInAnonymousNamespace(), allOf(isConstexpr(), hasAncestor(recordDecl()))))
6866
.bind("var_decl"),
6967
this);
7068

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace clang::tidy::readability {
1717
/// declarations.
1818
///
1919
/// For the user-facing documentation see:
20-
/// http://clang.llvm.org/extra/clang-tidy/checks/readability/readability-redundant-inline-specifier.html
20+
/// http://clang.llvm.org/extra/clang-tidy/checks/readability/redundant-inline-specifier.html
2121
class RedundantInlineSpecifierCheck : public ClangTidyCheck {
2222
public:
2323
RedundantInlineSpecifierCheck(StringRef Name, ClangTidyContext *Context)

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ class C
2828
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'operator=' has inline specifier but is implicitly inlined [readability-redundant-inline-specifier]
2929
// CHECK-FIXES: C& operator=(const C&) = delete;
3030

31+
inline C(const C&) = default;
32+
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'C' has inline specifier but is implicitly inlined [readability-redundant-inline-specifier]
33+
3134
constexpr inline C& operator=(int a);
3235
// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: function 'operator=' has inline specifier but is implicitly inlined [readability-redundant-inline-specifier]
3336
// CHECK-FIXES: constexpr C& operator=(int a);
@@ -76,7 +79,7 @@ static constexpr inline int fn1(int i)
7679
namespace
7780
{
7881
inline int fn2(int i)
79-
// CHECK-MESSAGES-NOT: :[[@LINE-1]]:5: warning: function 'fn2' has inline specifier but is implicitly inlined [readability-redundant-inline-specifier]
82+
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'fn2' has inline specifier but is implicitly inlined [readability-redundant-inline-specifier]
8083
{
8184
return i - 1;
8285
}
@@ -87,6 +90,9 @@ namespace
8790
{
8891
return i - 1;
8992
}
93+
94+
inline constexpr int MY_CONSTEXPR_VAR = 42;
95+
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: variable 'MY_CONSTEXPR_VAR' has inline specifier but is implicitly inlined [readability-redundant-inline-specifier]
9096
}
9197

9298
namespace ns

0 commit comments

Comments
 (0)