public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/109405] New: Should class final decoration result in larger unique_ptr with deleter ?
@ 2023-04-04 13:18 gcc at hazlewoods dot net
  2023-04-04 13:36 ` [Bug c++/109405] " redi at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: gcc at hazlewoods dot net @ 2023-04-04 13:18 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109405

            Bug ID: 109405
           Summary: Should class final decoration result in larger
                    unique_ptr with deleter ?
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gcc at hazlewoods dot net
  Target Milestone: ---

Whilst making an attempt to ensure some `std::unique_ptr<>` types had size
`sizeof(intptr_t)`, I was using empty `struct` deleters.
I habitually tapped `final` on a struct, and was surprised to see my
`static_assert`s fire.

Maybe this is a consequence of the push for devirtualization optimization, but
hopefully this can be confirmed.

```
#include <iostream>
#include <memory>

int main()
{
    struct S { void operator()() {} };
    struct SF final { void operator()() {} };
    std::cout << "S : " << sizeof(S) << std::endl;
    std::cout << "SF: " << sizeof(SF) << std::endl;

    using SP = std::unique_ptr<int, S>;
    using SFP = std::unique_ptr<int, SF>;
    std::cout << "SP : " << sizeof(SP) << std::endl;
    std::cout << "SFP: " << sizeof(SFP) << std::endl;
}
```


https://godbolt.org/z/Gfz4W5sP1

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/109405] Should class final decoration result in larger unique_ptr with deleter ?
  2023-04-04 13:18 [Bug c++/109405] New: Should class final decoration result in larger unique_ptr with deleter ? gcc at hazlewoods dot net
@ 2023-04-04 13:36 ` redi at gcc dot gnu.org
  2023-04-04 13:41 ` gcc at hazlewoods dot net
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2023-04-04 13:36 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109405

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |ABI

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
This is expected. The unique_ptr implementation uses tuple<int*, SF> which is
similarly dependent on whether the tuple elements are final or not. Originally,
that was because we used inheritance in tuple, in order to take advantage of
the empty-base class optimization. Obviously we can't use inheritance for final
types.

These days we do not use inheritance, we use the [[no_unique_address]]
attribute so that empty tuple elements take no space. But to avoid an ABI
incompatibility with previous versions of GCC, the attribute is only used for
non-final types.

There's no way to fix this without breaking the library's ABI.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/109405] Should class final decoration result in larger unique_ptr with deleter ?
  2023-04-04 13:18 [Bug c++/109405] New: Should class final decoration result in larger unique_ptr with deleter ? gcc at hazlewoods dot net
  2023-04-04 13:36 ` [Bug c++/109405] " redi at gcc dot gnu.org
@ 2023-04-04 13:41 ` gcc at hazlewoods dot net
  2023-04-05  9:30 ` [Bug libstdc++/109405] " xry111 at gcc dot gnu.org
  2023-04-05 11:12 ` redi at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: gcc at hazlewoods dot net @ 2023-04-04 13:41 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109405

--- Comment #2 from Richard Hazlewood <gcc at hazlewoods dot net> ---
Ah, ok.  Thanks for quick response.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug libstdc++/109405] Should class final decoration result in larger unique_ptr with deleter ?
  2023-04-04 13:18 [Bug c++/109405] New: Should class final decoration result in larger unique_ptr with deleter ? gcc at hazlewoods dot net
  2023-04-04 13:36 ` [Bug c++/109405] " redi at gcc dot gnu.org
  2023-04-04 13:41 ` gcc at hazlewoods dot net
@ 2023-04-05  9:30 ` xry111 at gcc dot gnu.org
  2023-04-05 11:12 ` redi at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: xry111 at gcc dot gnu.org @ 2023-04-05  9:30 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109405

Xi Ruoyao <xry111 at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |WONTFIX
                 CC|                            |xry111 at gcc dot gnu.org
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #3 from Xi Ruoyao <xry111 at gcc dot gnu.org> ---
WONTFIX then.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug libstdc++/109405] Should class final decoration result in larger unique_ptr with deleter ?
  2023-04-04 13:18 [Bug c++/109405] New: Should class final decoration result in larger unique_ptr with deleter ? gcc at hazlewoods dot net
                   ` (2 preceding siblings ...)
  2023-04-05  9:30 ` [Bug libstdc++/109405] " xry111 at gcc dot gnu.org
@ 2023-04-05 11:12 ` redi at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2023-04-05 11:12 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109405

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
It's possible to fix for the --enable-symvers=gnu-versioned-namespace build
which does not promise a backwards compatible ABI. I didn't do that yet, I
*think* it was because support for [[no_unique_address]] was still patchy in
Clang and other non-GCC compilers. Maybe that's no longer an issue and it could
be done now.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-04-05 11:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-04 13:18 [Bug c++/109405] New: Should class final decoration result in larger unique_ptr with deleter ? gcc at hazlewoods dot net
2023-04-04 13:36 ` [Bug c++/109405] " redi at gcc dot gnu.org
2023-04-04 13:41 ` gcc at hazlewoods dot net
2023-04-05  9:30 ` [Bug libstdc++/109405] " xry111 at gcc dot gnu.org
2023-04-05 11:12 ` redi at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).