11
11
#include " clang/ASTMatchers/ASTMatchFinder.h"
12
12
#include " clang/ASTMatchers/ASTMatchers.h"
13
13
#include " clang/Basic/Diagnostic.h"
14
+ #include " clang/Lex/Lexer.h"
14
15
#include " clang/Sema/DeclSpec.h"
15
16
16
17
using namespace clang ::ast_matchers;
@@ -41,7 +42,7 @@ void RedundantTypenameCheck::registerMatchers(MatchFinder *Finder) {
41
42
}
42
43
43
44
void RedundantTypenameCheck::check (const MatchFinder::MatchResult &Result) {
44
- const SourceLocation TypenameKeywordLoc = [&] {
45
+ const SourceLocation ElaboratedKeywordLoc = [&] {
45
46
if (const auto *TTL =
46
47
Result.Nodes .getNodeAs <TypedefTypeLoc>(" typedefTypeLoc" ))
47
48
return TTL->getElaboratedKeywordLoc ();
@@ -53,14 +54,24 @@ void RedundantTypenameCheck::check(const MatchFinder::MatchResult &Result) {
53
54
if (const auto DNTL = InnermostTypeLoc.getAs <DependentNameTypeLoc>())
54
55
return DNTL.getElaboratedKeywordLoc ();
55
56
57
+ if (const auto TSTL =
58
+ InnermostTypeLoc.getAs <TemplateSpecializationTypeLoc>())
59
+ return TSTL.getElaboratedKeywordLoc ();
60
+
56
61
return SourceLocation ();
57
62
}();
58
63
59
- if (TypenameKeywordLoc.isInvalid ())
64
+ if (ElaboratedKeywordLoc.isInvalid ())
65
+ return ;
66
+
67
+ if (Token ElaboratedKeyword;
68
+ Lexer::getRawToken (ElaboratedKeywordLoc, ElaboratedKeyword,
69
+ *Result.SourceManager , getLangOpts ()) ||
70
+ ElaboratedKeyword.getRawIdentifier () != " typename" )
60
71
return ;
61
72
62
- diag (TypenameKeywordLoc , " redundant 'typename'" )
63
- << FixItHint::CreateRemoval (TypenameKeywordLoc );
73
+ diag (ElaboratedKeywordLoc , " redundant 'typename'" )
74
+ << FixItHint::CreateRemoval (ElaboratedKeywordLoc );
64
75
}
65
76
66
77
} // namespace clang::tidy::readability
0 commit comments