public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/104653] New: Derived class looks for a definition of its inherited constexpr virtual destructor
@ 2022-02-23  7:25 lichray at gmail dot com
  2022-02-23  7:46 ` [Bug c++/104653] " pinskia at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: lichray at gmail dot com @ 2022-02-23  7:25 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 104653
           Summary: Derived class looks for a definition of its inherited
                    constexpr virtual destructor
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: lichray at gmail dot com
  Target Milestone: ---

The following -std=c++20 code fails to compile:

#include <cstddef>

struct B {
    virtual ~B() = default;
};

struct D : B {};

struct C : B {};

bool foo(std::byte *p) {
    constexpr D obj;
    return __builtin_memcmp(p, &obj, sizeof(void *)) == 0;
}

<source>: In function 'bool foo(std::byte*)':
<source>:12:17: error: 'virtual constexpr D::~D()' used before its definition
   12 |     constexpr D obj;
      |                 ^~~

The code compiles in MSVC 19.29 and Clang 10.

GCC seems to understand that D inherited a defaulted, constexpr virtual
destructor, but reports that it needs a definition. The problem doesn't arise
if D is dependent. A workaround is the following:

struct D : B {
    virtual constexpr ~D() override;
};

constexpr D::~D() = default;

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

* [Bug c++/104653] Derived class looks for a definition of its inherited constexpr virtual destructor
  2022-02-23  7:25 [Bug c++/104653] New: Derived class looks for a definition of its inherited constexpr virtual destructor lichray at gmail dot com
@ 2022-02-23  7:46 ` pinskia at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-02-23  7:46 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |DUPLICATE

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Dup of bug 93413.

*** This bug has been marked as a duplicate of bug 93413 ***

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

end of thread, other threads:[~2022-02-23  7:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-23  7:25 [Bug c++/104653] New: Derived class looks for a definition of its inherited constexpr virtual destructor lichray at gmail dot com
2022-02-23  7:46 ` [Bug c++/104653] " 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).