Skip to content

[clang] Failure when upcasting to a base class in trailing return type expression #114024

Open
@carlosgalvezp

Description

@carlosgalvezp

Hi,

Consider this example code:

struct Base
{};

int foo(Base&);

struct Derived : Base
{
    auto f() & -> decltype(foo(static_cast<Base&>(*this)))
    {
        return foo(static_cast<Base&>(*this));
    }
};

Clang emits this failure:

<source>:9:32: error: non-const lvalue reference to type 'Base' cannot bind to a value of unrelated type 'Derived'
    9 |     auto f() & -> decltype(foo(static_cast<Base&>(*this)))
      |  

Repro.

However, GCC, MSVC and EDG accept the code. I am confused as to why Clang complains; a Derived class should be possible to upcast to its base?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"diverges-from:edgDoes the clang frontend diverge from edg compilerdiverges-from:gccDoes the clang frontend diverge from gcc on this issuediverges-from:msvcDoes the clang frontend diverge from msvc on this issuerejects-valid

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions