moves-rwth / storm

A Modern Probabilistic Model Checker
https://www.stormchecker.org
GNU General Public License v3.0
126 stars 73 forks source link

Inconsistent `STORM_PRINT` and `STORM_PRINT_AND_LOG` macros #551

Closed tquatmann closed 1 month ago

tquatmann commented 1 month ago

The above-mentioned macros are not surrounded by do{ ... } while(false) as the other similar macros. This is somewhat of a hack to enforce that macro invocations are terminated with a ;. It seems that one can also just drop the ; after std::cout.flush().

The current state might trigger warnings when a ; is added anyway, see for example the discussion on #547

https://github.com/moves-rwth/storm/blob/f50c3282cc6642949b6f33868206c54aafed8a81/src/storm/utility/macros.h#L52-L73

AlexBork commented 1 month ago

To document this: dropping the ; after std::cout.flush() does not work, I get the following compile error.

In file included from .../storm/src/storm/api/export.cpp:1:
In file included from .../storm/src/storm/api/export.h:7:
.../storm/src/storm/io/file.h:27:9: error: expected ';' after expression
        STORM_PRINT_AND_LOG("Write to file " << filepath << ".\n");
        ^
.../storm/src/storm/utility/macros.h:71:9: note: expanded from macro 'STORM_PRINT_AND_LOG'
        STORM_PRINT(message);        \
        ^
.../storm/src/storm/utility/macros.h:66:5: note: expanded from macro 'STORM_PRINT'
    }
    ^
1 error generated.

The problem appears to be the enclosing braces which are necessary to ensure correct behaviour.

AlexBork commented 1 month ago

Having looked into it, the do {...} while (false) construction seems to be best practice, see for example https://gcc.gnu.org/onlinedocs/cpp/Swallowing-the-Semicolon.html