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

DCHECK_NOTNULL generates "expression result unused" errors with clang in strict compilation mode #172

Closed
joydeep-b opened this issue Mar 25, 2017 · 1 comment

Comments

@joydeep-b
Copy link

joydeep-b commented Mar 25, 2017

Synopsis:
When compiling a program in release mode, treating warnings as errors (-DNDEBUG -Wall -Werror), the use of DCHECK_NOTNULL results in "expression result unused" errors when compiling with clang.

Steps to reproduce:

  1. Enter the following contents in a file named test.cc:
#include "glog/logging.h"

void Foo(int* x) {
  DCHECK_NOTNULL(x);
  *x = 42;
}

int main() {
  int a = 0;
  Foo(&a);
}
  1. Compile the program with:
clang++ -Werror -Wall test.cc -lglog -o test -DNDEBUG

This will result in the following output:

test.cc:4:18: error: expression result unused [-Werror,-Wunused-value]
  DCHECK_NOTNULL(x);
                 ^
/usr/include/glog/logging.h:1042:30: note: expanded from macro 'DCHECK_NOTNULL'
#define DCHECK_NOTNULL(val) (val)
                             ^~~
1 error generated.
@joydeep-b joydeep-b changed the title DCHECK* generates "expression result unused" errors with clang in strict compilation mode DCHECK_NOTNULL generates "expression result unused" errors with clang in strict compilation mode Mar 25, 2017
@chen3feng
Copy link

chen3feng commented Nov 6, 2020

I fixed this issue by this change in our internal codebase:

// A small helper for DCHECK_NOTNULL().
template <typename T>
T* NotCheckNotNull(T* t) {
  return t;
}

#define DCHECK_NOTNULL(val) (::google::NotCheckNotNull(val))

FYI.

@sergiud sergiud closed this as completed Mar 30, 2021
@sergiud sergiud mentioned this issue May 6, 2021
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

No branches or pull requests

3 participants