@@ -1453,6 +1453,9 @@ PointerAssignmentGadget::getFixits(const FixitStrategy &S) const {
1453
1453
return std::nullopt;
1454
1454
}
1455
1455
1456
+ // / \returns fixit that adds .data() call after \DRE.
1457
+ static inline std::optional<FixItList> createDataFixit (const ASTContext& Ctx, const DeclRefExpr * DRE);
1458
+
1456
1459
std::optional<FixItList>
1457
1460
PointerInitGadget::getFixits (const FixitStrategy &S) const {
1458
1461
const auto *LeftVD = PtrInitLHS;
@@ -1870,6 +1873,18 @@ PointerDereferenceGadget::getFixits(const FixitStrategy &S) const {
1870
1873
return std::nullopt;
1871
1874
}
1872
1875
1876
+ static inline std::optional<FixItList> createDataFixit (const ASTContext& Ctx, const DeclRefExpr * DRE) {
1877
+ const SourceManager &SM = Ctx.getSourceManager ();
1878
+ // Inserts the .data() after the DRE
1879
+ std::optional<SourceLocation> EndOfOperand =
1880
+ getPastLoc (DRE, SM, Ctx.getLangOpts ());
1881
+
1882
+ if (EndOfOperand)
1883
+ return FixItList{{FixItHint::CreateInsertion (*EndOfOperand, " .data()" )}};
1884
+
1885
+ return std::nullopt;
1886
+ }
1887
+
1873
1888
// Generates fix-its replacing an expression of the form UPC(DRE) with
1874
1889
// `DRE.data()`
1875
1890
std::optional<FixItList>
@@ -1878,14 +1893,7 @@ UPCStandalonePointerGadget::getFixits(const FixitStrategy &S) const {
1878
1893
switch (S.lookup (VD)) {
1879
1894
case FixitStrategy::Kind::Array:
1880
1895
case FixitStrategy::Kind::Span: {
1881
- ASTContext &Ctx = VD->getASTContext ();
1882
- SourceManager &SM = Ctx.getSourceManager ();
1883
- // Inserts the .data() after the DRE
1884
- std::optional<SourceLocation> EndOfOperand =
1885
- getPastLoc (Node, SM, Ctx.getLangOpts ());
1886
-
1887
- if (EndOfOperand)
1888
- return FixItList{{FixItHint::CreateInsertion (*EndOfOperand, " .data()" )}};
1896
+ return createDataFixit (VD->getASTContext (), Node);
1889
1897
// FIXME: Points inside a macro expansion.
1890
1898
break ;
1891
1899
}
0 commit comments