We properly warn about: $ cat /tmp/unused.c static void foo() { } $ gcc /tmp/unused.c -c -Wall /tmp/unused.c:1:13: warning: ‘foo’ defined but not used [-Wunused-function] static void foo() ^~~ but not about: $ cat /tmp/unused.c static inline void foo() { } Clang does that: $ clang /tmp/unused.c -c -Wall /tmp/unused.c:1:20: warning: unused function 'foo' [-Wunused-function] static inline void foo() ^ 1 warning generated.
This is done on purpose as static inline functions are located in many headers files including gcc's.
Note I ran into this bug with clang with the vpp project sources too.
Andrew I don't get it. Can you please explain why it does not make sense to warn e.g. about function that are declared in a .c file (not header file)?
Like these addressed here: https://gcc.gnu.org/ml/gcc-patches/2018-09/msg01317.html
Test the warning out on clang from a header file and you will see you get the warning in the header too. As I said I actually ran into this while working on the vpp project and cursed clang for having this warning turned on.
I think for C++ (which is the component this bug was created for, even if comment 0 only has C examples) it makes sense to warn even for static inline functions in headers ... why would you want to define them in headers? In C++ they should probably just be inline, not static inline. Even if we don't want the warning for headers, it does make sense for functions defined in .C files.
Again I ran into this stupid bug in clang and had to use preprocessor macros to work around it. I dont think we should change the behavior of gcc of this warning at all. In fact as I said I ran into a bug due to it suggestion in clang.
Why do you want to have static inline functions in headers in C++? Why do you want to have static inline functions NOT in headers in C++?
It was in a header file. Clang still earned about it.
That's not what I asked. Anyway, see comment 3. We're not talking about what Clang does, we're asking why it would be invalid for GCC to implement this warning. Maybe it would make sense only for code that is not in headers (IMHO it makes sense in headers too, which is why I asked why you want such code in headers, but I could accept having the warning only for code outside headers). Insisting it's stupid to warn about code in headers doesn't make it invalid to warn about code outside headers. Please address the questions instead of just closing it again.
It's probably inconvenient for C indeed (pre-dating C99 inline). Even GCC has too many static inlines in headers. I agree that we can warn for static inline declarations with locations that are not in any included file (not sure how exactly to verify that).
(In reply to Richard Biener from comment #11) > I agree that we can warn for static inline declarations with locations that > are not in any included file (not sure how exactly to verify that). MAIN_FILE_P() ?
(In reply to Andrew Pinski from comment #5) > Test the warning out on clang from a header file and you will see you get > the warning in the header too. As I said I actually ran into this while > working on the vpp project and cursed clang for having this warning turned > on. I think something similar happened with the gdb project; I'll try to find it later...
(In reply to Eric Gallager from comment #13) > (In reply to Andrew Pinski from comment #5) > > Test the warning out on clang from a header file and you will see you get > > the warning in the header too. As I said I actually ran into this while > > working on the vpp project and cursed clang for having this warning turned > > on. > > I think something similar happened with the gdb project; I'll try to find it > later... Right, found it, thread starting here: https://sourceware.org/ml/gdb/2015-02/msg00045.html cc-ing people from it. Also, corresponding clang bug is here: https://bugs.llvm.org/show_bug.cgi?id=22712