Archived issue #0032402

Coding Rules - eliminate msvc warning C4668 (symbol is not defined as a preprocessor macro, replacing with '0' for directive)

CommunityOCCT:Codingclosed16 public notes

Search issues

Description

Some headers, like Standard_Macro.hxx, contain preprocessor macros for platform dependent code.
Some of this code like f.e.

#elif (defined(__GNUC__) && __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) || defined(__clang__)

is not consistent with respect to guard expressions.

Although both, the C and the C++ standard, explicitly allow using undefined identifiers and replace them with '0', see f.e. N3797, 16.1.4 (p. 402)

"After all replacements due to macro expansion and the defined unary operator
have been performed, all remaining identifiers and keywords149, except for true and false, are replaced with the pp-number 0, and then each preprocessing token is converted into a token"

a expression which consistently uses these rules would, using the example of the #elif above, be either

#elif (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))) || defined(__clang__)

or

#elif (defined(__GNUC__) && __GNUC__ > 4 || (defined(__GNUC__) && __GNUC__ == 4 && __GNUC_MINOR__ >= 6)) || defined(__clang__)

or

#elif (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) || defined(__clang__)

so that either all binary expressions are guarded by a unary one or none of them.

Although this is trivial, it reduces the noise during compilation for compilers where the value use of undefined preprocessor identifiers can be enabled as a warning; f.e. GCC provides the "-Wundef" flag and newer versions of Visual Studio seem to have this enabled per default when using /Wall.

Steps to reproduce

Compile with and without the changes; the latter should result in more warnings for certain compilers and/or compiler options on the changed lines; f.e. GCCs "-Wundef"

Public activity

16 archived notes

Participants are labeled by their role within this record.

01Commenter 2
Branch [archived branch] has been created by Author.

[revision removed]


Detailed log of new commits:

Author: zaphod
Date: Sun May 30 12:27:19 2021 +0200

    0032402: make preprocessor expressions consistent with respect to guard expressions
02Commenter 3
-#if __QNX__
+#if defined(__QNX__) && __QNX__

There is no point checking __QNX__ for value - it was supposed to be just "#if defined(__QNX__)" with "defined" being lost by mistake.
03Author
That's true.
I was trying to preserve the exact same semantics and if __QNX__ could be defined to #define __QNX__ 0 they would change. But i don't know much about qnx and likely such a definition is defined to be invalid in that context.
04Commenter 3
If you are considering patch for integration and it is ready - please switch bug into RESOLVED state.

05Author
If that comment was directed to me, i have to admit that i either don't know how to do it or am not allowed to do it; there's no option shown; i'm only allowed to reassign.
About the __QNX__ define, i don't know where to check all possible values for __QNX__. I'll happily make another commit which changes the check to your suggestion if you like.

Btw, i also did the same for "Standard_JmpBuf.hxx"
#elif IRIX
to
#elif defined(IRIX) && IRIX

06Commenter 2
Branch [archived branch] has been created by Commenter 3.

[revision removed]


Detailed log of new commits:

Author: Commenter 3
Date: Tue Jun 1 10:28:36 2021 +0300

    Configuration, genproj - add EnableAllWarnings to generated msvc projects
07Commenter 2
Branch [archived branch] has been created by Commenter 3.

[revision removed]


Detailed log of new commits:

Author: Commenter 3
Date: Tue Jun 1 10:58:40 2021 +0300

    # genproj, temporarily enable C4668
    
    #- <AdditionalOptions>%(AdditionalOptions)</AdditionalOptions>
    #+ <AdditionalOptions>/w34668 %(AdditionalOptions)</AdditionalOptions>
08Commenter 2
Branch [archived branch] has been updated by Commenter 3.

[revision removed]


Detailed log of new commits:

Author: zaphod
Date: Sun May 30 12:27:19 2021 +0200

    0032402: Coding Rules - eliminate msvc warning C4668 (symbol is not defined as a preprocessor macro, replacing with '0' for directive)
    
    Make preprocessor expressions consistent with respect to guard expressions.

09Commenter 2
Branch [archived branch] has been updated by Commenter 3.

[revision removed]


Detailed log of new commits:

Author: Commenter 3
Date: Tue Jun 1 11:37:25 2021 +0300

    Fixed usage of macros OCCT_DEBUG, DO_INVERSE, DRAW, CHFI3D_DEB by value.
    Removed obsolete hack for Sun Workshop 5.0 compiler.

10Commenter 2
Branch [archived branch] has been created by Commenter 3.

[revision removed]


Detailed log of new commits:

Author: zaphod
Date: Sun May 30 12:27:19 2021 +0200

    0032402: Coding Rules - eliminate msvc warning C4668 (symbol is not defined as a preprocessor macro, replacing with '0' for directive)
    
    Make preprocessor expressions consistent with respect to guard expressions.
    
    Fixed usage of macros __QNX__, IRIX, OCCT_DEBUG, DO_INVERSE, DRAW, CHFI3D_DEB by value.
    Removed obsolete hack for Sun Workshop 5.0 compiler.
11Commenter 3
Please raise the patch
- OCCT: branch CR32402_2;
- OCC Products: branch CR32402_2.

http://jenkins-test-occt/view/CR32402_2-CR32402_2-KGV/
12Commenter 1
Combination -
OCCT branch : [archived branch]
master SHA - [revision removed]
[revision removed]
Products branch : [archived branch] SHA - [revision removed]
was compiled on Linux, MacOS and Windows platforms and tested in optimize mode.

Number of compiler warnings:
No new/fixed warnings

Regressions/Differences/Improvements:
No regressions/differences

CPU differences:
Debian80-64:
OCCT
Total CPU difference: 17503.060000000427 / 17574.5700000004 [-0.41%]
Products
Total CPU difference: 11532.860000000106 / 11533.700000000124 [-0.01%]
Windows-64-VC14:
OCCT
Total CPU difference: 19219.09375 / 19393.5625 [-0.90%]
Products
Total CPU difference: 12831.25 / 12891.8125 [-0.47%]


Image differences :
No differences that require special attention

Memory differences :
No differences that require special attention
13Commenter 2
Branch [archived branch] has been deleted by Participant.

[revision removed]
14Commenter 2
Branch [archived branch] has been deleted by Participant.

[revision removed]
15Commenter 2
Branch [archived branch] has been deleted by Participant.

[revision removed]
16Commenter 2
Branch [archived branch] has been deleted by Participant.

[revision removed]