Does the function header return an abstract type of law?

I was wondering that according to the C ++ standard, the following was completed:

struct Abstract { virtual ~Abstract() = 0; }; auto get_type() -> Abstract; // I use `get_type` only to extract the return type. using MyType = decltype(get_type()); 

GCC 6.3 accepts it, but Clang 3.9 rejects it.

However, if I do this:

 auto get_type() -> struct Abstract; struct Abstract { virtual ~Abstract() = 0; }; using MyType = decltype(get_type()); 

Now both compilers accept it. Are they both wrong in this case?

+8
c ++ language-lawyer abstract-class c ++ 11
source share
1 answer

In [class.abstract] is pretty simple:

An abstract class should not be used as a parameter type, as a function return type, or as an explicit conversion type.

Any code that tries to do this is poorly formed.

+10
source share

All Articles