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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
            Summary|Feature request: improve    |missing -Waddress for
                   |"-Waddress" (or equivalent) |member references
                   |for function references     |
                   |inside structs              |
                 CC|                            |msebor at gcc dot gnu.org
   Last reconfirmed|                            |2021-11-22

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
Confirmed with GCC 12.  Since the warning is issued for non-member references
(the first case below) but not for members (the second case) I would consider
this a bug rather than an enhancement request.

$ cat pr96507.C && gcc -S -Wall pr96507.C
typedef void F ();

extern F &fr;
extern int &ir;

bool gfun ()
{
  return &fr != 0;   // -Waddress (expected)
}

bool gvar ()
{
  return &ir != 0;   // -Waddress (expected)
}


struct S
{
  F &fr;
  int &ir;
};

extern S s;

bool hfun ()
{
  return &s.fr != 0; // missing warning
}

bool hvar ()
{
  return &s.ir != 0; // missing warning
}

pr96507.C: In function ‘bool gfun()’:
pr96507.C:8:14: warning: the compiler can assume that the address of ‘fr’ will
never be NULL [-Waddress]
    8 |   return &fr != 0;   // -Waddress (expected)
      |          ~~~~^~~~
pr96507.C:3:11: note: ‘fr’ declared here
    3 | extern F &fr;
      |           ^~
pr96507.C: In function ‘bool gvar()’:
pr96507.C:13:14: warning: the compiler can assume that the address of ‘ir’ will
never be NULL [-Waddress]
   13 |   return &ir != 0;   // -Waddress (expected)
      |          ~~~~^~~~
pr96507.C:4:13: note: ‘ir’ declared here
    4 | extern int &ir;
      |             ^~

Reply via email to