https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98639

            Bug ID: 98639
           Summary: GCC accepts cast from Base to Derived in C++20 mode
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: arthur.j.odwyer at gmail dot com
  Target Milestone: ---

// https://godbolt.org/z/96EEPa
struct Base {};
struct Derived : Base {};
Derived t() { Base b; return Derived(b); }

// https://godbolt.org/z/G4covG
auto lam = [i=42]() { return i; };
struct Derived : decltype(lam) {
    bool is_derived() const { return true; }
};
Derived t() { return Derived(lam); }

I actually suspect that this behavior is related to C++20's paren-init for
aggregates; it might even be conforming? But there's no way this behavior was
*intentional.* A value of type Base shouldn't be castable to Derived.

static_cast<Derived>(b) is also accepted by GCC.

Reply via email to