Clang 抱怨 "cannot override a deleted function" 而没有删除任何功能

Clang complains "cannot override a deleted function" while no function is deleted

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

#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 抱怨 "non-deleted function '~C' cannot override a deleted function": 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 is undefined (until C++11)defined as deleted (since C++11) if any of the following is true:

[...]

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 中,即

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

[...]

(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.

我遇到了同样的问题。 @decltype_auto 说这是 C++11 的特性。所以我使用选项“-std=c++98”来绕过这个问题。