News:

Simutrans Tools
Know our tools that can help you to create add-ons, install and customize Simutrans.

Standard macro expansion

Started by An_dz, July 07, 2017, 06:48:16 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

An_dz

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:
QuoteNew 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:
QuoteIf the defined operator appears as a result of a macro expansion, the C standard says the behavior is undefined.

And C99 spec says:
Quote6.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?

Ters

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.)

An_dz

 ;D I'm on Arch, always living dangerously ;D

Dwachs

Parsley, sage, rosemary, and maggikraut.

An_dz