The International Simutrans Forum

Development => Patches & Projects => Incorporated Patches and Solved Bug Reports => Topic started by: An_dz on July 07, 2017, 06:48:16 PM

Title: Standard macro expansion
Post by: An_dz on July 07, 2017, 06:48:16 PM
I've updated to GCC 7 and I started to receive thousands of warnings about 'this use of "defined" may not be portable', I looked further into it and found that with GCC 7 the flag -Wexpansion-to-defined is included with -Wextra or -Wpedantic and we use -Wall.

From GCC Changelog (https://gcc.gnu.org/gcc-7/changes.html#c-family):
Quote
New command-line options have been added for the C and C++ compilers:
[...]
-Wexpansion-to-defined warns when defined is used outside #if. This warning is enabled by -Wextra or -Wpedantic.

According to GCC docs (https://gcc.gnu.org/onlinedocs/cpp/Defined.html):
Quote
If the defined operator appears as a result of a macro expansion, the C standard says the behavior is undefined.

And C99 spec says (http://www.open-std.org/jtc1/sc22/WG14/www/docs/n1256.pdf):
Quote
6.10.1.4

Prior to evaluation, macro invocations in the list of preprocessing tokens that will become the controlling constant expression are replaced (except for those macro names modified by the defined unary operator), just as in normal text. If the token defined is generated as a result of this replacement process or use of the defined unary operator does not match one of the two specified forms prior to macro replacement, the behavior is undefined.

This patch fixes this, making the code follow the standard by moving the defines outside the macro expansions and creating flags for them. Any objections for committing this?
Title: Re: Standard macro expansion
Post by: Ters on July 07, 2017, 08:44:22 PM
Looks safe.

GCC 7? And I'm still hesitating to upgrade to GCC 5, due to what appear to be an ABI break. (Which means I'll have to recompile the entire system. Even if my system isn't running a dinosaur park, that is not trivial.)
Title: Re: Standard macro expansion
Post by: An_dz on July 07, 2017, 10:16:57 PM
 ;D I'm on Arch, always living dangerously ;D
Title: Re: Standard macro expansion
Post by: Dwachs on July 08, 2017, 11:20:33 AM
please commit
Title: Re: Standard macro expansion
Post by: An_dz on July 08, 2017, 12:15:58 PM
In r8256