Given a (inline void-returning nullary) function f
that doesn't have side effects:
inline void f() { /*...*/ }
Is it possible to write an inline function g
that calls f
but won't be optimized out by the implementation:
inline void g() { [[dont_optimize_this_away ???]] f(); }
Is there some way to tell the compiler "call f and inline the assembly, but don't optimize those instructions away"?
I don't think there is a way to do this in standard C++20. (or is there?)
...but is there a platform-specific way to do it on x86-64
with gcc
, clang
and/or msvc
? Some kind of instrinsic / compile builtin / attribute?