#1663 commctrl.h macros trigger -Waddress warnings in gcc 4.6.2

MinGW (57)

In gcc 4.6.2, the macros ListView_GetItemRect and ListView_GetSubItemRect in commctrl.h test that one of their arguments (the RECT pointer) is non-NULL before using it. When you enable -Waddress (or -Wall) and pass a local RECT variable to either macro, this triggers a warning that the address can never be NULL.

OS: Windows 7 32-bit

sh-3.1$ gcc -v
Using built-in specs.
Target: mingw32
Configured with: ../gcc-4.6.2/configure --enable-languages=c,c++,ada,fortran,objc,obj-c++ --disable-sjlj-exceptions --with-dwarf2 --enable-shared --enable-libgomp --disable-win32-registry --enable-libstdcxx-debug --enable-version-specific-runtime-libs --build=mingw32 --prefix=/mingw
Thread model: win32
gcc version 4.6.2 (GCC)

sh-3.1$ ld -v
GNU ld (GNU Binutils) 2.22

Test program:

#include <windows.h>
#include <commctrl.h>

int main()
ListView_GetItemRect(NULL, 0, &r, 0);
ListView_GetSubItemRect(NULL, 0, 0, 0, &r);

return 0;


Compiled via:

g++ -o test.exe test.cpp -Waddress -D_WIN32_IE=0x0300

Compiler output:

test.cpp: In function 'int main()':
test.cpp:7:3: warning: the address of 'r' will always evaluate as 'true' [-Waddress]
test.cpp:8:3: warning: the address of 'r' will always evaluate as 'true' [-Waddress]


  • Earnie Boyd

    Earnie Boyd - 2012-10-26

    Yes, the address of a variable will always be non zero.

  • Earnie Boyd

    Earnie Boyd - 2012-10-26
    • milestone: --> Behaves_as_Documented
    • status: open --> closed-invalid
  • Josh Townzen

    Josh Townzen - 2012-10-26

    The problem is that this is the proper way to use either of these two macros; you create a local RECT variable and pass it to the macro to get the result. The caller isn't interested in the implementation details of the macro, and shouldn't be getting a false-positive warning for using it correctly. I was hoping there was a way to rewrite the macros without triggering this warning, though if there is, I haven't been able to find it.

  • Earnie Boyd

    Earnie Boyd - 2013-01-21
    • status: closed-invalid --> closed
    • resolution: --> invalid
    • category: --> Behaves_as_Documented
    • milestone: Behaves_as_Documented --> WSL

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks