[Bug c++/106107] New: dynamic_cast fail within constant expression

pkeir at outlook dot com gcc-bugzilla@gcc.gnu.org
Mon Jun 27 16:39:36 GMT 2022


            Bug ID: 106107
           Summary: dynamic_cast fail within constant expression
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pkeir at outlook dot com
  Target Milestone: ---

Created attachment 53210
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53210&action=edit
The code described in the bug report.

The dynamic_cast, evaluated within the static_assert, in the code below, fails
(GCC trunk); while the runtime assert passes. Both pass with Clang and MSVC.

I have in place a workaround for the lack of an implicit destructor in Derived
due to bug 93413 - I am not sure if this is independent of that 93413.

#include <cassert>

struct Base {
  virtual constexpr ~Base() {}

struct Derived : public Base
#if !defined(__clang__)
  // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93413
  constexpr virtual ~Derived() {};

constexpr bool test()
  Base* bp = new Derived;
  Derived* dp = dynamic_cast<Derived *>(bp);
  bool b = dp != nullptr;
  delete bp;
  return b;

int main(int argc, char *argv[])


  return 0;

More information about the Gcc-bugs mailing list