Does cppcheck issue a warning for small functions that are not declared inline? I can't remember ever seeing one. It is an optimisation that has existed for a long time but is easily neglected. Many functions now are declared with constexpr which makes an implicit inline declaration from C++11.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Well, personally I am a bit skeptic about it. Cppcheck does not have detailed knowledge about the compiler and hardware. Probably the compiler inlines small functions anyway if that makes sense.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
To use inline on small functions is recommended by C++ Core Guidelines F5. It says inline isn't required for function templates but unless they are defined within a class definition they are not inplicitly declared inline.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
alright. if we implement a c++ core guidelines ruleset it certainly makes sense to implement this. It sounds like a good idea to implement that ruleset.
Last edit: Daniel Marjamäki 2023-10-07
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I can't see a negative side to it other than too much inlining. Someone thought it was worthwhile making constexpr functions implicitly declared inline.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Does cppcheck issue a warning for small functions that are not declared inline? I can't remember ever seeing one. It is an optimisation that has existed for a long time but is easily neglected. Many functions now are declared with constexpr which makes an implicit inline declaration from C++11.
There is no warning to declare a function inline.
Well, personally I am a bit skeptic about it. Cppcheck does not have detailed knowledge about the compiler and hardware. Probably the compiler inlines small functions anyway if that makes sense.
To use inline on small functions is recommended by C++ Core Guidelines F5. It says inline isn't required for function templates but unless they are defined within a class definition they are not inplicitly declared inline.
alright. if we implement a c++ core guidelines ruleset it certainly makes sense to implement this. It sounds like a good idea to implement that ruleset.
Last edit: Daniel Marjamäki 2023-10-07
I can't see a negative side to it other than too much inlining. Someone thought it was worthwhile making constexpr functions implicitly declared inline.
I find that many potentialy inlined functions are defined in a .cpp file and called from another translation unit.