https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115670
--- Comment #3 from Federico Kircheis <federico at kircheis dot it> --- I've collected the example mentioned here and in my original report https://godbolt.org/z/o4893zhPs ~~~~ struct { int i = 42; } const a; auto foo0(){ return a; } int foo1(decltype(a)&){ return 1; } decltype(a) foo2(){ return a; } namespace { struct s{}; s foo3(){ return {}; } } s foo4(){ return {}; } auto foo5(){ struct {} t; return t; } ~~~~ Except for foo0 and foo5, `-Wunused-function` emits a diagnostic (should I make a separate issue for the warning?) > GCC is able to change the linkage of bar. it is just auto which is not > handled. As you can se in the emitted code, even if GCC changes the linkage (I'm sorry, I did not verify that), it still generates the corresponding code. I suppose that that code can be discarded later by the linker. In the case of MSVC, as far as I've understood, as the function is never used, no code is emitted (less work for the linker). I guess that a more generic approach would be that all unused code (all code that triggers a diagnostic with -Wunused-function could be avoided...