typedef-name as base class: illegal but widely tolerated
The first paragraph of [class.derived] says of base class specifiers,
If the name开发者_运维技巧 found is not a class-name, the program is ill-formed.
However, a simple test shows that Comeau and g++ -ansi -pedantic
both accept a typedef-name as a base. A simple grep -r '[^:]: mpl'
over the Boost headers shows that popular library often relies on such behavior.
Has any compiler ever actually rejected a typedef
of a class in a base specifier? GCC even checks that the base class type is not const
, which refines the nonstandard functionality.
Is there a workaround? The only thing I can think of is to replace the typedef with a C++11 alias template. A templated alias-declaration declares a template-name which may then become a class-name… I think. This may require a dummy parameter to the alias-declaration.
Perhaps the Standard should be adjusted to match the unanimous behavior of the compilers. Is there a DR?
I believe this is in accordance with the standard. Specifically, §9.1/5: "A typedef-name (7.1.3) that names a class is a class-name, [...]".
精彩评论