This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

C++: -fstrict-prototypes problems


Currently, g++ will reject the program

extern "C" void foo();
void foo(int);

int main()
{
  foo();
}

It says

a.cc:2: too few arguments to function `void foo (int)'
a.cc:6: at this point in file

I think this is wrong, for a number of reasons:

- the documentation says that you can pass -pedantic to change the
  behaviour. However, in this case, -pedantic should not apply:
  -pedantic should make g++ only reject code which would be accepted
  without it; in this case, -pedantic results in acceptance of code
  which is rejected without it

- if this is an extension of g++ which gives a different meaning to
  code under -ansi, then passing -ansi should enable the standard
  behaviour, i.e. g++ should accept it. -ansi does not change
  anything.

To have this code compile, you need to pass -fstrict-prototype. The
problem is that g++ considers the second declaration as a
redeclaration of the first, which it isn't.

I see a number of different solutions:
- Totally remove support for -fno-strict-prototype from g++.
- Toggle the setting of flag_strict_prototype, so people have to pass
  -fno-strict-prototype to compile C++ code on systems where the system
  headers don't offer proper prototypes.
- Don't treat the second declaration as a redeclaration of the first, even
  with -fno-strict-prototype.

What do y'all think?

Regards,
Martin


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]