This is the mail archive of the gcc-help@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]
Other format: [Raw text]

Extra semicolons in C++.


Hello all,

I have been wondering this for a really long time now, since it was
changed in GCC. In a C source file compiled with -pedantic, an extra
semicolon would produce the following error, of course:

test.c:9: warning: ISO C does not allow extra `;' outside of a function

I'm assuming this is for the reason it says: because ISO C doesn't
allow extra semicolons.

What I've always wondered is, why does compiling a C++ file with g++
-pedantic produce errors about extra semicolons as well?

test.cpp:9: error: extra `;'

I though that extra semicolons were perfectly valid in C++. Is this
not true? Somebody on another mailing list recently pointed out to me
(and this is what brought up this question), that the C++ standard
says:

   statement:
expression-statement
compound-statement
...

   expression-statement:
expression_opt ;

   compound-statement:
{ statement-seq_opt }

And the _opt items are optional. So a single semicolon and nothing
else is a valid "expression statement" and therefore a valid
"statement". Is something being interpreted wrong here?

Thanks!
Jason

P.S. Here is the test program:

int main (int argc, char **argv) {

  if (0) {
  } else {
  };

  return 0;;

};


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