<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/93066>93066</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [Clang] Add a fix-it hint for `++this` -> `++*this`
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            enhancement,
            good first issue,
            clang:frontend,
            clang:diagnostics
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          Sirraide
      </td>
    </tr>
</table>

<pre>
    There was a suggestion to add a fix-it hint that would correct `++this` to `++*this` following a discussion about #92439 now that we diagnose the former even in dependent contexts. From what I can tell, this would entail adding a fix-int (probably in `CheckForModifiableLvalue` in SemaExpr.cpp) that inserts a `*` before the expression, if 
 - it is of pointer type, and
 - the expression itself is not a modifiable lvalue, and
 - the pointee type is modifiable (i.e. don’t suggest `++this` -> `++*this` in a `const` member function).

Notably, doing this in `CheckForModifiableLvalue` would cover more cases than just `++`. Possible test cases I can think of would be:
```c++
void f(int* a, int* const b, const int* const c, __UINTPTR_TYPE__ d) {
    (int*)d = 4; // Suggest a fixit; `(int*)d` is a prvalue.
    ++a;         // No fixit; this is fine.
    ++b;         // Suggest a fixit; `b` is const but `*b` isn’t.
    ++c;         // No fixit; `++c` is invalid, but so is `++*c`.
}

struct S {
    void f() { 
        // Suggest a fixit. `++*this` is probably what the user meant.
        //
        // Note: if this is in a template, then we generally won’t have
        // any way of knowing whether there even is an overload of `++` 
        // for this type, but it makes sense to assume there is because
        // it’s unlikely that a user would just try and increment it any-
        // way if that was the case.
        ++this; 
    }

    void g() const { 
        // No fixit here. Of course, one *could* define an overload of
        // `++` that is `const`, but doing so would be rather confusing
        // considering what this operator usually does, so most people
        // won’t do that and suggesting a `*` therefore would just lead
        // to a lot of false positives.
        ++this; 
    }
};
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVstu47gS_Rp6U4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