Archive for the 'C++' Category

Visual C++: Letting C++ programmers get away with new murder without warning

Consider Visual C++.

This always correct code emits a completely useless warning:

 

 

This never ever correct code doesn’t emit any warning at all:

Visual C++ is a totally awesome piece of technology.  So why doesn’t it work the way I want it to?

‘typename’ is not always a substitute for ‘class’ in a template parameter

You know the C++ rule that says that the keyword ‘typename’ can be used interchangably with ‘class’ in a template parameter?  Not always!  Not for the keyword ‘class’ that appears after the template parameter of a template template parameter!

This is a syntax error:

You must write it like this:

Why is that?  Jonathan Caves explains here that the rule ‘typename’ can be used interchangably with ‘class’ is a semantic rule, but the use of ‘class’ in the template template parameter is a syntax rule, and thus takes precedence.

Oversight? Intentional?

By the way, Visual C++ 2012 gives a really unhelpful pair of error messages for this, one of which includes an internal grammar rule name—and that is really non-optimal for a compiler error message: