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

WSL
closed
nobody
MinGW (56)
invalid
Behaves_as_Documented
2014-08-16
2012-08-09
Josh Townzen
No

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.
COLLECT_GCC=C:\MinGW\BIN\gcc.exe
COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/4.6.2/lto-wrapper.exe
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()
{
RECT r;
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]

Discussion

  • 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