public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/106107] New: dynamic_cast fail within constant expression
@ 2022-06-27 16:39 pkeir at outlook dot com
  2022-10-22 22:40 ` [Bug c++/106107] dynamic_cast for polymorphic types " pinskia at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: pkeir at outlook dot com @ 2022-06-27 16:39 UTC (permalink / raw)
  To: gcc-bugs

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

            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() {};
#endif
};

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[])
{
  static_assert(test());

  assert(test());

  return 0;
}

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug c++/106107] dynamic_cast for polymorphic types fail within constant expression
  2022-06-27 16:39 [Bug c++/106107] New: dynamic_cast fail within constant expression pkeir at outlook dot com
@ 2022-10-22 22:40 ` pinskia at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-10-22 22:40 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=93413
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2022-10-22
     Ever confirmed|0                           |1
            Summary|dynamic_cast fail within    |dynamic_cast for
                   |constant expression         |polymorphic types fail
                   |                            |within constant expression

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-10-22 22:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-27 16:39 [Bug c++/106107] New: dynamic_cast fail within constant expression pkeir at outlook dot com
2022-10-22 22:40 ` [Bug c++/106107] dynamic_cast for polymorphic types " pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).