Skip to content

Commit 1fc1375

Browse files
committed
feedback
1 parent 3354841 commit 1fc1375

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "UseSpanFirstLastCheck.h"
10-
#include "../utils/ASTUtils.h"
1110
#include "../utils/Matchers.h"
1211
#include "clang/AST/ASTContext.h"
13-
#include "clang/AST/RecursiveASTVisitor.h"
1412
#include "clang/ASTMatchers/ASTMatchFinder.h"
1513
#include "clang/ASTMatchers/ASTMatchers.h"
1614
#include "clang/Lex/Lexer.h"
@@ -25,6 +23,10 @@ void UseSpanFirstLastCheck::registerMatchers(MatchFinder *Finder) {
2523
hasType(hasUnqualifiedDesugaredType(recordType(hasDeclaration(
2624
classTemplateSpecializationDecl(hasName("::std::span"))))));
2725

26+
const auto SubspanDecl = cxxMethodDecl(
27+
hasName("subspan"),
28+
ofClass(classTemplateSpecializationDecl(hasName("::std::span"))));
29+
2830
// Match span.subspan(0, n) -> first(n)
2931
Finder->addMatcher(
3032
cxxMemberCallExpr(
@@ -64,10 +66,6 @@ void UseSpanFirstLastCheck::check(const MatchFinder::MatchResult &Result) {
6466
if (!SpanObj)
6567
return;
6668

67-
StringRef SpanText = Lexer::getSourceText(
68-
CharSourceRange::getTokenRange(SpanObj->getSourceRange()),
69-
*Result.SourceManager, Result.Context->getLangOpts());
70-
7169
const auto *SubSpan =
7270
Result.Nodes.getNodeAs<CXXMemberCallExpr>("first_subspan");
7371
bool IsFirst = true;
@@ -85,7 +83,9 @@ void UseSpanFirstLastCheck::check(const MatchFinder::MatchResult &Result) {
8583
StringRef CountText = Lexer::getSourceText(
8684
CharSourceRange::getTokenRange(Count->getSourceRange()),
8785
*Result.SourceManager, Result.Context->getLangOpts());
88-
86+
StringRef SpanText = Lexer::getSourceText(
87+
CharSourceRange::getTokenRange(SpanObj->getSourceRange()),
88+
*Result.SourceManager, Result.Context->getLangOpts());
8989
const StringRef FirstOrLast = IsFirst ? "first" : "last";
9090
std::string Replacement =
9191
(Twine(SpanText) + "." + FirstOrLast + "(" + CountText + ")").str();

clang-tools-extra/test/clang-tidy/checkers/readability/use-span-first-last.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,4 @@ void test_different_spans() {
147147
// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer 'span::last()' over 'subspan()'
148148
// CHECK-FIXES: auto good2 = s2.last(3);
149149
}
150+

0 commit comments

Comments
 (0)