@@ -1490,6 +1490,9 @@ PointerAssignmentGadget::getFixits(const FixitStrategy &S) const {
1490
1490
return std::nullopt;
1491
1491
}
1492
1492
1493
+ // / \returns fixit that adds .data() call after \DRE.
1494
+ static inline std::optional<FixItList> createDataFixit (const ASTContext& Ctx, const DeclRefExpr * DRE);
1495
+
1493
1496
std::optional<FixItList>
1494
1497
PointerInitGadget::getFixits (const FixitStrategy &S) const {
1495
1498
const auto *LeftVD = PtrInitLHS;
@@ -1907,6 +1910,18 @@ PointerDereferenceGadget::getFixits(const FixitStrategy &S) const {
1907
1910
return std::nullopt;
1908
1911
}
1909
1912
1913
+ static inline std::optional<FixItList> createDataFixit (const ASTContext& Ctx, const DeclRefExpr * DRE) {
1914
+ const SourceManager &SM = Ctx.getSourceManager ();
1915
+ // Inserts the .data() after the DRE
1916
+ std::optional<SourceLocation> EndOfOperand =
1917
+ getPastLoc (DRE, SM, Ctx.getLangOpts ());
1918
+
1919
+ if (EndOfOperand)
1920
+ return FixItList{{FixItHint::CreateInsertion (*EndOfOperand, " .data()" )}};
1921
+
1922
+ return std::nullopt;
1923
+ }
1924
+
1910
1925
// Generates fix-its replacing an expression of the form UPC(DRE) with
1911
1926
// `DRE.data()`
1912
1927
std::optional<FixItList>
@@ -1915,14 +1930,7 @@ UPCStandalonePointerGadget::getFixits(const FixitStrategy &S) const {
1915
1930
switch (S.lookup (VD)) {
1916
1931
case FixitStrategy::Kind::Array:
1917
1932
case FixitStrategy::Kind::Span: {
1918
- ASTContext &Ctx = VD->getASTContext ();
1919
- SourceManager &SM = Ctx.getSourceManager ();
1920
- // Inserts the .data() after the DRE
1921
- std::optional<SourceLocation> EndOfOperand =
1922
- getPastLoc (Node, SM, Ctx.getLangOpts ());
1923
-
1924
- if (EndOfOperand)
1925
- return FixItList{{FixItHint::CreateInsertion (*EndOfOperand, " .data()" )}};
1933
+ return createDataFixit (VD->getASTContext (), Node);
1926
1934
// FIXME: Points inside a macro expansion.
1927
1935
break ;
1928
1936
}
0 commit comments