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

DLOG_ASSERT bug for non-debug mode compilation? #711

Closed
zzh-wisdom opened this issue Sep 22, 2021 · 1 comment · Fixed by #1035
Closed

DLOG_ASSERT bug for non-debug mode compilation? #711

zzh-wisdom opened this issue Sep 22, 2021 · 1 comment · Fixed by #1035
Labels
Milestone

Comments

@zzh-wisdom
Copy link

An unexpected behavior of DLOG_ASSERT occured.

#define NDEBUG
#include <glog/logging.h>
#include <assert.h>

int main(int argc,char* argv[])
{
    FLAGS_logtostderr = 1;
    google::InitGoogleLogging(argv[0]);
    LOG(INFO) << "Hello,GLOG!";

    DLOG(DFATAL) << "DLOG!";
    DLOG_ASSERT(0);
 
    google::ShutdownGoogleLogging();
}

DLOG_ASSERT(0); should be compiled away to nothing for non-debug mode compiles while we got assertion failure.

I0922 10:14:15.887724 125488 demo.cc:15] Hello,GLOG!
F0922 10:14:15.887872 125488 demo.cc:25] Assert failed: 0
*** Check failure stack trace: ***
    @     0x7f94561461c3  google::LogMessage::Fail()
    @     0x7f945614b25b  google::LogMessage::SendToLog()
    @     0x7f9456145ebf  google::LogMessage::Flush()
    @     0x7f94561466ef  google::LogMessageFatal::~LogMessageFatal()
    @     0x555c53928360  main
    @     0x7f9455d710b3  __libc_start_main
    @     0x555c539281ae  _start
Aborted (core dumped)

Is this a bug?

We take advantage of g++ macro expansion to compile the code.

g++ -E -P demo.cc > demo1.cc

DLOG_ASSERT(0); is converted to

static_cast<void>(0), true ? (void) 0 : static_cast<void>(0), !(!(0)) ? (void) 0 : google::LogMessageVoidify() & google::LogMessageFatal( "demo22.cc", 12).stream() << "Assert failed: " "0";

Are there missing parentheses around static_cast<void>(0), !(!(0)) ? (void) 0 : google::LogMessageVoidify() & google::LogMessageFatal( "demo22.cc", 12).stream() << "Assert failed: " "0"; ?

@sergiud sergiud added the bug label Jan 5, 2024
@sergiud sergiud added this to the 0.7 milestone Jan 5, 2024
@sergiud
Copy link
Collaborator

sergiud commented Jan 5, 2024

Good catch. Yes, there are parentheses missing around LOG_ASSERT.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants