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