Reputation: 41840
I was wondering of the following was legal according to the C++ standard:
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 accept it, but Clang 3.9 reject it.
However, if I do this instead:
auto get_type() -> struct Abstract;
struct Abstract { virtual ~Abstract() = 0; };
using MyType = decltype(get_type());
Now both compiler accept it. Are they both wrong in this case?
Upvotes: 8
Views: 236
Reputation: 304122
In [class.abstract], pretty straightforwardly:
An abstract class shall not be used as a parameter type, as a function return type, or as the type of an explicit conversion.
Any code that tries to do such a thing is ill-formed.
Upvotes: 10