In the GHS compiler, if you have multiple semicolons in a row without any intervening statements, this generates a diagnostic message (warning). For example:
void myfunc()
{
}; // warning #381-D: extra ';' ignored.
This doesn't seem like a very common situation, but this warning is also issued after preprocessing has occurred, such that, the following would also generate the warning (when compiled in release):
#if _DEBUG
#define DEBUG_VAR(x) x
#else
#define DEBUG_VAR(x)
#endif
void myfunc()
{
}
// global variable, used only in debug
DEBUG_VAR(int x); // warning #381-D: extra ';' ignored.
I realize that there are easy ways to workaround this in this case, it is just an illustrative example. There are many other situations with the preprocessor where you might end up with a similar construct.
Obviously, the code is legal c++, and I have never encountered such a warning message on any other compiler I have used. Is there some reasonable explanation of why this warning would be helpful, for example, is there a specific case where this warning might indicate a programming error?
Most cases, surely?
Since the
;
has no meaning, either you wrote it as a redundancy (and then you have to ask "why?") or — and this is the key — you wrote it by accidentally deleting some code before it, or by getting something else wrong that confused the parser and made the;
look like it were redundant when, in fact, it weren't.Off the top of my head, though, I can't think of an example.
But that macro would be better written like so: