[Bug c++/104653] New: Derived class looks for a definition of its inherited constexpr virtual destructor
lichray at gmail dot com
gcc-bugzilla@gcc.gnu.org
Wed Feb 23 07:25:02 GMT 2022
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;
More information about the Gcc-bugs
mailing list