https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126746
Bug ID: 126746
Summary: trivial_abi attribute class with just declared
destructor erroneously destroyed twice
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: ivan.lazaric.gcc at gmail dot com
Target Milestone: ---
```cpp
#include <cstdio>
struct [[clang::trivial_abi]] A {
A();
~A();
};
[[gnu::noinline]]
void consume(auto) {}
void use_A() { consume(A{}); }
int main() {
use_A();
}
[[gnu::weak]]
A::~A(){
puts("destroy");
}
[[gnu::weak]]
A::A(){
puts("create");
}
```
Flags: "-std=c++26 -O3"
gcc emits destructor call in both callee and caller,
whereas clang only in callee
Running the program above, gcc emits:
```
create
destroy
destroy
```
clang emits:
```
create
destroy
```
https://godbolt.org/z/7MYxvMs4f