https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96498
Jonathan Wakely <redi at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Ever confirmed|0 |1 Status|UNCONFIRMED |NEW Last reconfirmed| |2020-08-06 --- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> --- This happens even if the function has already been declared at namespace scope prior to the friend declaration in the class template: __attribute__((nonnull(1))) void foo(void*); template<typename> struct T { friend void foo(void*); }; void bar() { foo(0); T<int> t; foo(0); } attr.C: In function 'void bar()': attr.C:11:8: warning: argument 1 null where non-null expected [-Wnonnull] 11 | foo(0); | ^ attr.C:1:34: note: in a call to function 'void foo(void*)' declared 'nonnull' 1 | __attribute__((nonnull(1))) void foo(void*); | ^~~ attr.C:13:8: warning: argument 1 null where non-null expected [-Wnonnull] 13 | foo(0); | ^ attr.C:5:15: note: in a call to function 'void foo(void*)' declared 'nonnull' 5 | friend void foo(void*); | ^~~ attr.C:12:10: warning: unused variable 't' [-Wunused-variable] 12 | T<int> t; | ^ I think the friend in the template should not change anything here, since the function is already visible.