1

I've got a C++ Xcode 3 project generated from CMake scripts. It uses some open-source headers which have always worked before but in this project I get a compile error Extra ';' when trailing brackets have an uneccessary semi-colon:

if(...)
{
...
};

Is there some compiler option which makes trailing semi-colons an error, which I can turn off?

Here is one of the offending files, see line 259: http://zziplib.svn.sourceforge.net/viewvc/zziplib/trunk/zzip-0/zzip/zzip.h?revision=523&view=markup

Mr. Boy
  • 60,845
  • 93
  • 320
  • 589
  • A semicolon following the closing `}` of an `if` statement should be perfectly legal. In that context, it's simply a null statement. You mention headers, so I suspect you actually have a stray semicolon after a declaration. Please show us an actual code snippet. Can you tell us what open source header you're using? Can you just fix the header? – Keith Thompson Sep 12 '12 at 08:58
  • @KeithThompson, added a link to the real file. – Mr. Boy Sep 12 '12 at 09:19

2 Answers2

5

The semicolon warning come courtesy of the -pedantic (or -pedantic-errors) option; I don't think you can disable it separately.

I'd recommend removing the semicolon rather than the warning.

Kerrek SB
  • 464,522
  • 92
  • 875
  • 1,084
  • Changing a stable, widely used FOSS project simply because one CMake script doesn't like it seems the wrong way to me! I'll report this to whoever maintains the CMake script, thanks. – Mr. Boy Sep 12 '12 at 08:56
  • @John: The header file is invalid C++. What do you expect the maintainer of the CMake script to do about it? The maintainer of zziplib should be willing to fix the errors. (I'll contact him myself.) – Keith Thompson Sep 12 '12 at 09:40
  • @John: The error is an extra semicolon following the closing `}` of the `extern "C"` in `plugin.h`, `zzip.h`, and `wrap.h`. I've sent the details to the authors. – Keith Thompson Sep 12 '12 at 09:54
  • If there's one thing experience has taught me is that "large" and "stable" code base does *not* mean "cleanly written". *Lots* of programmers are very inert creatures of habit who would much rather leave a piece of code "that works just fine" alone than touch it just to make it tidier. Perhaps rightly so, but it's a reality you'll have to face. – Kerrek SB Sep 12 '12 at 10:01
  • Yes I know but my issue is I've been using that lib for years on multiple OS without problems, some new version of a CMake script suddenly introduces the issue. @KeithThompson thanks, is it actually syntactically incorrect then? – Mr. Boy Sep 12 '12 at 10:20
  • @John: Yes, see the grammar for *linkage-specification* in section 7.5 of the [latest draft of the C++ standard](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3337.pdf), combined with the lack of empty declarations. – Keith Thompson Sep 12 '12 at 10:44
3

The extra semicolon in the sample code you showed us:

if(...)
{
...
};

is perfectly legal; it's a null statement.

The error you're getting is actually about an extra semicolon on an extern "C". The following appears in three source files in the zziplib library:

#ifdef __cplusplus
extern "C" {
#endif

...

#ifdef __cplusplus
};
#endif

This is in fact a syntax error. Some compilers might not complain about it, or might issue just a warning, but with g++ -pedantic-errors it's a fatal error.

I reported this problem to the maintainer of zziplib, and I've just gotten a reply:

Thanks for pointing to the problem, fixed in r524 now. I will
probably roll a public release next month (still need to check
the win32 version).

best regards, Guido Draheim

ChangeLog:

2012-09-15  guidod  <guidod@gmx.de>
    * zzip.h, plugin.h: "};" at end of extern-C produces build errors with
       the default --pedantic-errors on newer CMake. Thanks to Keith Thompson
       recognizing it - see http://stackoverflow.com/questions/12384280/
Keith Thompson
  • 254,901
  • 44
  • 429
  • 631