https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93414
Bug ID: 93414 Summary: Bad diagnostics for dynamic_cast during constant evaluation: implementation details leak out Product: gcc Version: 10.0 Status: UNCONFIRMED Keywords: diagnostic Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: antoshkka at gmail dot com Target Milestone: --- Consider the example that attempts to throw a std::bad_cast: struct Base { constexpr virtual ~Base(){} }; struct Derived: Base { constexpr ~Derived(){} }; constexpr const Derived& cast(const Base& b) { return dynamic_cast<const Derived&>(b); // error! } auto test() { static constexpr Base b; constexpr auto res = cast(b); return res; } The error message is following: <source>: In function 'constexpr const Derived& cast(const Base&)': <source>:10:42: error: call to non-'constexpr' function 'void* __cxa_bad_cast()' 10 | return dynamic_cast<const Derived&>(b); // error: call to non-'constexpr' function 'void* __cxa_bad_cast()' That's not informative: users usually know nothing about __cxa_bad_cast Please change the error message to something more informative, for example "During constexpr evaluation attempt to cast a variable `b` with typeid(b) == typeid(Base) to `Derived` was detected"