https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117465

            Bug ID: 117465
           Summary: Disable -Wnonnull-compare in macros
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: david.bolvansky at gmail dot com
  Target Milestone: ---

#include <cstdio>

#define DEBUG(ptr) if (ptr) printf("%p", (void *)ptr);

class Clz {
    int data;
public:
    Clz(void) {
        DEBUG(this);
    }
};

int main(void) {

    int i;
    DEBUG(&i);
    Clz a;

    return 0;
}

g++ -Wall -Wextra code.cpp

warning: 'nonnull' argument 'this' compared to NULL [-Wnonnull-compare]
    3 | #define DEBUG(ptr) if (ptr) printf("%p", (void *)ptr);



This is quite annoying in macros. Derived from real code, where null check is
needed, as macro is universal.

Reply via email to