Author Topic: Standard macro expansion  (Read 324 times)

0 Members and 1 Guest are viewing this topic.

Offline An_dz

  • Web Admin
  • Administrator
  • *
  • Posts: 2593
  • Total likes: 289
  • Helpful: 89
  • D'oh
    • by An_dz
  • Languages: PT, EN, (it, de)
Standard macro expansion
« 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:
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:
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:
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?

Offline Ters

  • Coder/patcher
  • Devotee
  • *
  • Posts: 4685
  • Total likes: 171
  • Helpful: 108
  • Languages: EN, NO
Re: Standard macro expansion
« Reply #1 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.)

Offline An_dz

  • Web Admin
  • Administrator
  • *
  • Posts: 2593
  • Total likes: 289
  • Helpful: 89
  • D'oh
    • by An_dz
  • Languages: PT, EN, (it, de)
Re: Standard macro expansion
« Reply #2 on: July 07, 2017, 10:16:57 PM »
 ;D I'm on Arch, always living dangerously ;D

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4224
  • Total likes: 168
  • Helpful: 148
  • Languages: EN, DE, AT
Re: Standard macro expansion
« Reply #3 on: July 08, 2017, 11:20:33 AM »
please commit
Parsley, sage, rosemary, and maggikraut.

Offline An_dz

  • Web Admin
  • Administrator
  • *
  • Posts: 2593
  • Total likes: 289
  • Helpful: 89
  • D'oh
    • by An_dz
  • Languages: PT, EN, (it, de)
Re: Standard macro expansion
« Reply #4 on: July 08, 2017, 12:15:58 PM »
In r8256