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

    <tr>
        <th>Summary</th>
        <td>
            [Clang] `++this` is accepted when it’s not instantiated
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang:frontend,
            accepts-invalid
      </td>
    </tr>

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

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

<pre>
    This code compiles, unless we instantiate and call `f()`. This doesn’t seem right to me because, irrespective of what the type of e.g. `this` ends up being, it’s a prvalue, and we can’t increment that.

```c++
template <typename T>
struct S : T {
    auto t() -> S*;
    void f() { 
        ++reinterpret_cast<S*>(4);
        ++this;
        ++t(); 
    }
};
```

Imo we should diagnose this earlier if that is feasible. GCC also suffers from the same problem, which caused `++this` as a typo for `++*this` to go unnoticed in a libstdc++ header because the template containing it was never instantiated by libstdc++. MSVC also accepts this code. Is this a bug or a standards defect? Because I don’t see a situation where `++this` would be semantically valid.

CC @AaronBallman, @cor3ntin, @erichkeane 
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx0VEFvszgQ_TXmMioiJiThwCFNmlUPe2q119VgD-BdYyN7SNR_vzKhbbqfvggFYXvem3lvxhij6R1RI6pnUZ0znHnwoXkzIaDRlLVefzTvg4mgvCZQfpyMpSjkCWZnKUa4ERgXGR0bZAJ0GhRaC2JXdEIehKzFrshhwdCeohMvUhwKUdcMkWiEYPqBgT2MBC0pnCMleBMCxYkUmyuB7-A2IAMPBPwxLQuU93li4cFEsSuAnI4wT9CScf2CwF9UERCmcEU7L9gpyRuBwsdkjFOBRnKJBTkXxVkUx_V_V9wfJeRzepZVpnGyqWZRnlJSDkeCd1G-3Lcjh1kxvIEoj_AOYr-GAQDgzB74Lg88ifIF3oQ8ivLhyNUbDauCKRi-t9Lvnkgg45jCFIj_VhhZlKc70IuQh23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