This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Extra semicolons in C++.
- From: "Jason Cipriani" <jason dot cipriani at gmail dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Thu, 24 Jan 2008 02:26:35 -0500
- Subject: 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;;
};