On Mon, Oct 4, 2021 at 2:43 PM Martin Sebor via Gcc-patches <gcc-patches@gcc.gnu.org> wrote: > > While resolving the recent -Waddress enhancement request (PR > PR102103) I came across a 2007 problem report about GCC 4 having > stopped warning for using the address of inline functions in > equality comparisons with null. With inline functions being > commonplace in C++ this seems like an important use case for > the warning. > > The change that resulted in suppressing the warning in these > cases was introduced inadvertently in a fix for PR 22252. > > To restore the warning, the attached patch enhances > the decl_with_nonnull_addr_p() function to return true also for > weak symbols for which a definition has been provided. > > Tested on x86_64-linux and by comparing the GCC output for new > test cases to Clang's which diagnoses all but one instance of > these cases with either -Wtautological-pointer-compare or > -Wpointer-bool-conversion, depending on context.
Would it make sense to use the same names as clang's flags here, too, instead of dumping them all under -Waddress? I think the additional granularity could be helpful for people who only want some warnings, but not others. > The one case where Clang doesn't issue a warning but GCC > with the patch does is for a symbol explicitly declared with > attribute weak for which a definition has been provided. > I believe the address of such symbols is necessarily nonnull and > so issuing the warning is helpful > (both GCC and Clang fold such comparisons to a constant). > > Martin