[clang] [clang] Fix-it hint for `++this` -> `++*this` when deref is modifiable (PR #94159)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Jun 2 21:07:54 PDT 2024
================
@@ -13587,10 +13587,22 @@ static bool CheckForModifiableLvalue(Expr *E, SourceLocation Loc, Sema &S) {
SourceRange Assign;
if (Loc != OrigLoc)
Assign = SourceRange(OrigLoc, OrigLoc);
- if (NeedType)
+ if (NeedType) {
S.Diag(Loc, DiagID) << E->getType() << E->getSourceRange() << Assign;
- else
+ } else {
+ ExprResult Deref;
+ unsigned FixitDiagID = 0;
+ {
+ Sema::TentativeAnalysisScope Trap(S);
+ Deref = S.ActOnUnaryOp(S.getCurScope(), Loc, tok::star, E);
+ }
S.Diag(Loc, DiagID) << E->getSourceRange() << Assign;
+ if (Deref.isUsable() &&
+ Deref.get()->isModifiableLvalue(S.Context, &Loc) == Expr::MLV_Valid) {
+ FixitDiagID = diag::note_typecheck_expression_not_modifiable_lvalue;
+ S.Diag(Loc, FixitDiagID) << E->getSourceRange() << Assign;
----------------
Sirraide wrote:
The `FixitDiagID` can just be inlined here.
This is also missing the actual fix-it hint; I’d suggest looking for uses of `FixItHint::CreateInsertion` and working with that.
https://github.com/llvm/llvm-project/pull/94159
More information about the cfe-commits
mailing list