I have the following code:
void check_portvalue(std::string_view value)
{
[[maybe_unused]] port_t test {value};
}
The object test remains unused, but creation serves as a check, because the constructor can throw.
The [[maybe_unused]] attribute suppresses the compiler warning.
But since the compiler detects that this is unused, could it optimize out the entire statement and thus prevent the exception from being thrown ?
Optimizer has to follow the as-if rule (i.e cannot change "observable behaviors")
The only exception to the as-if rule are:
Your code doesn't fall into those categories.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With