Skip to content

[Clang] ++this with a dependent this is accepted when it’s not instantiated #92439

@Sirraide

Description

@Sirraide

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.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions