I have a tiny header file in part of my project which defines a helper function like the following:
static std::string GetErrorString(const MyObj& obj)
{
// ... return the string
}
If I include this header in a source file where the function is not used, I get the following warning from MSVC:
warning C4505: 'GetErrorString': unreferenced local function has been removed
However, if I change the function to static inline
, the warning disappears. I have a couple of questions regarding this:
- The function still isn't used. Why does it being
inline
actually matter? - My understanding was that the
inline
keyword was merely a suggestion to the compiler, which in its infinite wisdom it is free to ignore. If this is the case, this implies thatinline
isn't actually the solution to this problem, because if the compiler decided not to inline the function then in theory I'd get the warning back again. What actually is the proper solution?