c++/3779: Accepts illegal C++ code: redefinition of default argument

Loren James Rittle rittle@latour.rsch.comm.mot.com
Tue Jul 24 03:40:00 GMT 2001


>> Before reporting standard compliance issues related to
>> gcc please try compiling with -pedantic.

> As the code in question is illegal C++, I believe it at least
> should give a warning no matter which flags are used.

Perhaps illegal, but mostly harmless [1] (except to portability-minded
people such as us).

So that you understand the reason I gave you the answer I did, here is
the documented stance of "the collective mind of the gcc maintainers"
(from the gcc info page):

``GCC always tries to compile your program if possible; it never
  gratuitously rejects a program whose meaning is clear merely because
  (for instance) it fails to conform to a standard.  In some cases,
  however, the C and C++ standards specify that certain extensions are
  forbidden, and a diagnostic _must_ be issued by a conforming
  compiler.  The `-pedantic' option tells GCC to issue warnings in
  such cases; `-pedantic-errors' says to make them errors instead.
  This does not mean that _all_ non-ANSI constructs get warnings or
  errors.''

There is similar section that explains why you might want to use -Wall
and/or -W with gcc since we don't like it to be noisy with warnings...

[...]
> In short: move the warning from -pedantic to all the time, and make 
>  it possible to force an error for this kind of illegal code.

[1] FYI: Since g++ currently does detect (and report by default) when
    there is a mismatch between the definition and redefinition of a
    default argument (i.e. a real problem), I'm not sure too many
    people are going to care about this issue in practice.  For your
    own happiness, I think it is better for you to learn to always use
    -pedantic...

Regards,
Loren



More information about the Gcc-bugs mailing list