https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102378
--- Comment #3 from Martin Sebor <msebor at gcc dot gnu.org> ---
With the correct explicit instantiation directive things look much better:
$ cat pr102378.C && gcc -S -Wall pr102378.C
int f ()
{
int a[2];
return &a == 0; // -Waddress (good)
}
template <class T>
int g ()
{
{
int a[2];
return &a == 0; // missing -Waddress
}
{
T t;
return &t == 0; // no -Waddress for type-dependent expr (good)
}
{
T a[2];
return &a == 0; // missing -Waddress
}
}
template <class T>
int h ()
{
{
int a[2];
return &a == 0; // -Waddress (good)
}
{
T t;
return &t == 0; // -Waddress (good)
}
{
T a[2];
return &a == 0; // -Waddress (good)
}
}
template int h<int> ();
pr102378.C: In function ‘int f()’:
pr102378.C:4:13: warning: the address of ‘a’ will never be NULL [-Waddress]
4 | return &a == 0; // -Waddress (good)
| ~~~^~~~
pr102378.C: In instantiation of ‘int h() [with T = int]’:
pr102378.C:45:22: required from here
pr102378.C:31:15: warning: the address of ‘a’ will never be NULL [-Waddress]
31 | return &a == 0; // -Waddress (good)
| ~~~^~~~
pr102378.C:36:15: warning: the address of ‘t’ will never be NULL [-Waddress]
36 | return &t == 0; // -Waddress (good)
| ~~~^~~~
pr102378.C:41:15: warning: the address of ‘a’ will never be NULL [-Waddress]
41 | return &a == 0; // -Waddress (good)
| ~~~^~~~