MSVC:非成员函数不允许使用修饰符

MSVC: modifiers not allowed on non-memberfunction

我在 linux 下写了一个 Signal/Slot 库 (Codeproject article here),用 Clang 3.5 和 GCC4.9 编译。它在两个编译器上编译时都没有警告(也在 3.4 版和 4.8 版上)。当我完成所有工作并将文章发布到网上时,没过多久我就收到投诉说它不能在 MSVC 上工作。 (Visual Studio Express 2013?不好意思,我对版本控制系统不熟悉。) 我把它安装在虚拟机上自己看了一下,发现它不会编译以下内容:

template <typename Signature>
struct RemoveCV;

template <typename R, typename ... Args>
struct RemoveCV<T, R (Args...)>
{
    using Type = R(Args...);
};

template <typename R, typename ... Args>
struct RemoveCV<T, R(Args...) const>
{
    using Type = R(Args...);
};

// more specializations for volatile and const volatile

// Usage:
template <typename Signature_>
struct Function
{
    using Signature = RemoveCV<Signature_>::Type;
};

// both Function<void()> and Function<void() const> now have 
// the same Signature: void()

原因是 R(Args ...) 不是成员函数,所以它不能有 const 限定符。

虽然在非成员函数上使用 const 限定符当然是没有意义的,但我相信我在某处读过(这里是 SO,包括来自标准的引述) ,只要它不绑定到实际功能,它就被允许。 IE。它 允许作为独立类型。不幸的是,我似乎再也找不到那个线程了...

我只是想知道这次谁是对的:MSVC 或 GCC + Clang,以及标准对像 void() const.

这样的独立函数签名有什么看法

好吧,关于标准的内容,我相信您(以及 GCC 和 Clang)似乎是正确的。来自 §8.3.5/6(在 N3376 中),(强调我的):

A cv-qualifier-seq or a ref-qualifier shall only be part of:

— the function type for a non-static member function,

— the function type to which a pointer to member refers,

— the top-level function type of a function typedef declaration or alias-declaration,

— the type-id in the default argument of a type-parameter (14.1), or

the type-id of a template-argument for a type-parameter (14.2).