[Bug c++/126746] New: trivial_abi attribute class with just declared destructor erroneously destroyed twice

"ivan.lazaric.gcc at gmail dot com via Gcc-bugs" <[email protected]>
Newsgroups gmane.comp.gcc.bugs
Message-ID <[email protected]/bugzilla/>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.