Clang抱怨“不能覆盖已删除的功能”而没有功能被删除 [英] Clang complains "cannot override a deleted function" while no function is deleted
问题描述
在以下简单代码片段中:
In the following simple code fragment:
#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
clang 3.7 complains that "non-deleted function '~C' cannot override a deleted function": http://goo.gl/Ax6oth
Visual Studio也没有GCC报告错误在这段代码。是蚌类缺陷还是什么?
Neither Visual Studio nor GCC report an error in this code. Is it a clang defect or what?
推荐答案
static void operator delete(void *, int);
不,
static void operator delete(void *, std::size_t);
且该类型差异会导致相关的歧义:
and that type difference causes an ambiguity that gets relevant:
类T的隐式声明或默认析构函数是
undefined(直到C ++ 11)定义为删除(因为C ++ 11)如果任何
以下是真的:
The implicitly-declared or defaulted destructor for class T is undefined (until C++11)defined as deleted (since C++11) if any of the following is true:
[...]
隐式声明的析构函数是虚拟的类
有一个虚拟析构函数)和释放的查找
函数(operator delete())导致调用模糊,删除,
或不可访问的函数。
The implicitly-declared destructor is virtual (because the base class has a virtual destructor) and the lookup for the deallocation function (operator delete() results in a call to ambiguous, deleted, or inaccessible function.
在标准(草案n4140)§12.4中是
And in the standard (draft n4140) §12.4 that is
5类X的默认析构函数定义为删除,如果:
5 A defaulted destructor for a class X is defined as deleted if:
[...]
5.3)或者,对于一个虚拟析构函数,查找非数组
释放函数导致一个模糊度或在
被删除或从默认析构函数不可访问的函数中。
(5.3) or, for a virtual destructor, lookup of the non-array deallocation function results in an ambiguity or in a function that is deleted or inaccessible from the defaulted destructor.
这篇关于Clang抱怨“不能覆盖已删除的功能”而没有功能被删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!