gpt4 book ai didi

c++11 - Clang 提示 "cannot override a deleted function"而没有删除任何功能

转载 作者:行者123 更新时间:2023-12-03 22:27:29 28 4
gpt4 key购买 nike

在以下简单的代码片段中:

#include <cstddef>

struct B
{
virtual ~B() = default;
static void operator delete(void *, int);
static void * operator new(size_t, int);
};

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

clang 3.7 提示“未删除的函数 '~C' 无法覆盖已删除的函数”:
http://goo.gl/Ax6oth

Visual Studio 和 GCC 都不报告此代码中的错误。这是 clang 缺陷还是什么?

最佳答案

static void operator delete(void *, int);

不,它是
 static void operator delete(void *, std::size_t);
并且这种类型差异会导致相关的歧义:
cppreference.com has

The implicitly-declared or defaulted destructor for class T isundefined (until C++11)defined as deleted (since C++11) if any of thefollowing is true:

[...]

The implicitly-declared destructor is virtual (because the base classhas a virtual destructor) and the lookup for the deallocationfunction (operator delete() results in a call to ambiguous, deleted,or inaccessible function.


在标准(n4140 草案)§12.4 中,

5 A defaulted destructor for a class X is defined as deleted if:

[...]

(5.3) or, for a virtual destructor, lookup of the non-arraydeallocation function results in an ambiguity or in a function that isdeleted or inaccessible from the defaulted destructor.

关于c++11 - Clang 提示 "cannot override a deleted function"而没有删除任何功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33626088/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com