https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128898
Bug ID: 128898
Summary: Code after contract terminate is not optimized out
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: jg at jguk dot org
Target Milestone: ---
Latest gcc C++ trunk. Was pleased to try out C++26 Contracts.
After __tu_terminate_wrapper() calls std::terminate(), the process exits with
SIGABRT.
Therefore I had expected both LC0 and LC1 strings to not be present in the
assembler and output by puts() after. Perhaps there is a way to mark the
terminate as noreturn, unreachable after.
See that f() is inlined into main in the assembler
Output:
terminate called without an active exception
Program terminated with signal SIGABRT (6)
g++ -O3 -Wall --std=c++26 -fcontracts
https://godbolt.org/z/9vos55jxT
#include <cstdio>
#include <contracts>
static void handle_contract_violation(std::contracts::contract_violation const
& here)
{
}
static void f(double divisor)
pre(0.0 != divisor)
{
if(divisor == 0.0)
{
std::printf("oops f bug\n");
}
}
int main()
{
f(0.0);
std::printf("f finished\n");
}
"__tu_terminate_wrapper()":
push rax
call "std::terminate()"
.LC0:
.string "oops f bug"
.LC1:
.string "f finished"
"main":
sub rsp, 8
call "__tu_terminate_wrapper()"
mov edi, OFFSET FLAT:.LC0
call "puts"
mov edi, OFFSET FLAT:.LC1
call "puts"
xor eax, eax
add rsp, 8
ret