If I throw in the destructor of a struct/class and compile with Werror=terminate, the compiler will complain with the following error message:
warning: 'throw' will always call 'terminate' [-Wterminate]
Compiler: GCC 11.1.0
If I however do this the compiler doesn't complain:
#include <iostream>
# define FORCE_INLINE __attribute__((always_inline)) inline
FORCE_INLINE void exception_proxy() {
throw std::invalid_argument("HI");
}
struct T {
T() = default;
~T() {
exception_proxy();
}
};
int main()
{
}
Why is this the case? I am trying to understand exactly why the compiler drops the warning when the function is inlined? I understand that the compiler doesn't care to check each function called from a noexcept function but this seems a bit counterintuitive given my knowledge?
Godbolt link to show actual inlining: https://godbolt.org/z/eGW7ov9av