Skip to content

C++ Insights - Episode 1: The invisible things - Invalid ImplicitCast #313

@andreasfertig

Description

@andreasfertig

In C++ Insights - Episode 1: The invisible things there is an example:

struct A {};
struct B {
   explicit operator A() { return {}; }
};

void DangerousFunc(const A&) {}

int main()
{
  DangerousFunc(static_cast<A>(B{}));
}

The transformation that C++ Insights shows leads to:

DangerousFunc(static_cast<A>(static_cast<A>(B{}.operator A())));

which is incorrect. The first static_cast<A> is missing const.

It was initially reported by @peterkochlarsen and @DanielKhoshnoud.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions