[Bug c/102967] confusing location in -Waddress for a subexpression of a ternary expression
amachronic at protonmail dot com
gcc-bugzilla@gcc.gnu.org
Mon Sep 19 19:57:28 GMT 2022
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102967
Aidan MacDonald <amachronic at protonmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |amachronic at protonmail dot com
--- Comment #9 from Aidan MacDonald <amachronic at protonmail dot com> ---
I am also hitting this with GCC 12.2. One more detail to add is that the info
manual says the -Waddress warning should be suppressed if it's a result of a
macro expansion. This does indeed happen when the macro is the only thing in
the conditional, but not when the macro is part of a larger expression.
Example (https://godbolt.org/z/YEY4Yzdnf):
#include <stddef.h>
#define MACRO(buf, off) (off < 0 ? NULL : (void*)&buf[off])
void func(char *buf, long off)
{
if (off < 0 ? NULL : (void*)&buf[off]) { } // warning (correct)
if (!(off < 0 ? NULL : (void*)&buf[off])) { } // warning (correct)
if (MACRO(buf, off)) { } // no warning (correct)
if (!MACRO(buf, off)) { } // gives a false positive -Waddress
}
More information about the Gcc-bugs
mailing list