MSVC: Modifiers Not Allowed for Non-Member Function

I wrote the Signal / Slot library ( Codeproject article here ) under Linux, compiling both Clang 3.5 and GCC4.9. It compiles without warning on both compilers (also in versions 3.4 and 4.8). When I got everything that worked and published an article on the Internet, it did not take much time until I had complaints that it did not work on MSVC. (Visual Studio Express 2013? Sorry, I'm not familiar with the version control system.) I installed it in a virtual machine to look at myself and found that it did not compile the following:

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

The reason is that R(Args ...) not a member function, so it cannot have a const qualifier.

Although it is true that it makes no sense to have a const qualifier for a function that is not a member, I believe that I read somewhere (here on SO, including a quote from the standard) that this is until it is associated with the actual function. That is, it is allowed as an autonomous type. Unfortunately, I seem to be unable to find this thread anymore ...

I'm just wondering who exactly about this: MSVC or GCC + Clang, and what the standard has to say about the autonomous function signature, for example void() const .

+8
c ++ c ++ 11
source share
1 answer

Well, I think it seems that you (both GCC and Clang) are right about the standard. From ยง8.3.5 / 6 (in N3376), (my attention):

A cv-qualifier-seq or ref-qualifier should be part of:

- type of function for a non-static member function,

- type of function to which the pointer to the element belongs,

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

- type identifier in the default argument of type parameter (14.1) or

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

+5
source share

All Articles