Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure marcos always expand to expressions #604

Merged
merged 1 commit into from
Jan 3, 2018

Conversation

sam-lunt
Copy link

@sam-lunt sam-lunt commented Jan 3, 2018

Currently, the SPDLOG_TRACE and SPDLOG_DEBUG expand to nothing if they are disabled, but this can lead to problems. assert expands to (void)0 when NDEBUG is defined, so I use the same here.

A couple of possible problems that could happen with the current definitions:

This is valid when SPDLOG_DEBUG_ON is defined, but expands to ,; (which is an error) if not:

SPDLOG_DEBUG(logger, "x = {}", x), SDPLOG_DEBUG(logger, "y = {}", y);

If SPDLOG_DEBUG_ON is defined, this is a compilation error, but if not defined then then if statement actually catches the assignment to b:

bool b;
if (b)
    SPDLOG_DEBUG(logger, "b was true")
b = false;

@gabime
Copy link
Owner

gabime commented Jan 3, 2018

Good catch. Thanks

@gabime gabime merged commit 32177aa into gabime:master Jan 3, 2018
@sam-lunt sam-lunt deleted the improve-macros branch January 3, 2018 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants