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

            Bug ID: 102258
           Summary: dynamic_cast to derived type fails during constant
                    evaluation
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Keywords: rejects-valid
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: johelegp at gmail dot com
                CC: johelegp at gmail dot com
  Target Milestone: ---

See https://godbolt.org/z/dsEzaxW47.
```C++
struct B { virtual ~B() = default; };
struct D : B { constexpr ~D() override { } };
int main() {
  []() consteval {
    B* b = new D;
    dynamic_cast<D&>(*b);
    delete b;
  }();
}
```
```
<source>: In function 'int main()':
<source>:8:4:   in 'constexpr' expansion of '<lambda closure
object>main()::<lambda()>().main()::<lambda()>()'
<source>:6:5: error: reference 'dynamic_cast' failed
    6 |     dynamic_cast<D&>(*b);
      |     ^~~~~~~~~~~~~~~~~~~~
<source>:6:5: note: dynamic type 'D [1]' of its operand does not have a base
class of type 'D'
Compiler returned: 1
```

Reply via email to