Bug in g++ using -pedantic option.

Martin v. Loewis martin@mira.isdn.cs.tu-berlin.de
Mon May 31 21:06:00 GMT 1999


> Implicit or not, it doesn't help to specify it explicit neither. This
> 
>     B(A<T>::value v)
> 
> is just as little helpful.

Indeed. In standard C++, A<T>::value is not a type, but syntactically
an expression - You can't know what it is for sure until you know what
T is. To denote a type in a 'dependent name', you have to use the
keyword typename. Changing it to

      B(typename A<T>::value v)

will make g++ accept it.

> It was quite a job to reverse engineer the problem and figure out
> that I needed a second and implicit defined template parameter in
> the base class to make -pedantic react, since this wasn't excactly
> obvious.

I can't really say I'm sorry. There is an error in the C++ code, and
any good C++ book will tell you what the error is. That egcs 1.1
doesn't always catch the error is unfortunate, but you would have been
better off assuming an error in your code instead of assuming an error
in the compiler.

> As far as it comes to the error message provided, I think it could
> be an idea to make the error message a bit more informative and
> exact about what the problem is. As is, it looks like the compiler
> is in trouble not knowing exactly what it asserts, just that it gets
> in trouble.

If you work with g++ some time, you'll find out that "parse error
before <parameter name>" typically means "parameter type is not a
type". It is unfortunate that the diagnostic is not better, but there
is really nothing that can be done about it short of rewriting the C++
parser in g++. Please contact Mark Mitchell if you are interested in
funding such a project.

Normally, when the compiler flags a pedantic error, it knows exactly
what the user wanted to do, and says that it just isn't standard
C++. Not in this case:

g++ supports an extension called the 'implicit typename extension',
where it inserts the typename keyword in places where it is
syntactically required, but missing in the source code. With
-pedantic, no implicit keyword is added, so the compiler doesn't
consider 'value' to as a typename, which results in the parse error.
At that time, it is too late to go back an see whether inserting
'typename' earlier would have helped.

Regards,
Martin



More information about the Gcc-bugs mailing list