Is there a way in C++ to declare that a function has no side effects? Consider:
LOG("message").SetCategory(GetCategory());
Now suppose that the LOG macro in release builds creates a NullLogEntry object that has SetCategory() defined as an empty function. So basically the whole expression could (and should) be optimized away -- expcept that, in theory, the GetCategory() call may have some side effects, so I guess the compiler is not permitted to just throw it away.
Another example could be a function template specialization that ignores some (or all) of its arguments, yet the compiler is not allowed to save the evaluation of such arguments at the call site due to possible side effects.
Am I right? Or can compilers optimize away such calls anyway? If not, is there a way to hint the compiler that this function has no side effects, so if the return value is ignored then the whole call can be skipped?