public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/98995] New: Copy elision not applied to members declared with [[no_unique_address]]
@ 2021-02-08  0:53 david at doublewise dot net
  2021-02-08  9:36 ` [Bug c++/98995] [11 Regression] " rguenth at gcc dot gnu.org
                   ` (14 more replies)
  0 siblings, 15 replies; 16+ messages in thread
From: david at doublewise dot net @ 2021-02-08  0:53 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 98995
           Summary: Copy elision not applied to members declared with
                    [[no_unique_address]]
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: david at doublewise dot net
  Target Milestone: ---

The following valid translation unit is rejected by gcc 11:

```
struct non_movable {
        non_movable() = default;
        non_movable(non_movable &&) = delete;
};

struct wrapper {
        constexpr explicit wrapper(auto function):
                m(function())
        {
        }

        [[no_unique_address]] non_movable m;
};

constexpr auto w = wrapper{[]{ return non_movable(); }};
```

with the error message

```
<source>: In instantiation of 'constexpr wrapper::wrapper(auto:1) [with auto:1
= <lambda()>]':
<source>:15:55:   required from here
<source>:8:17: error: use of deleted function
'non_movable::non_movable(non_movable&&)'
    8 |                 m(function())
      |                 ^~~~~~~~~~~~~
<source>:3:9: note: declared here
    3 |         non_movable(non_movable &&) = delete;
      |         ^~~~~~~~~~~
Compiler returned: 1
```

See it live: https://godbolt.org/z/o1TbY9

This was accepted in gcc 10.2.

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

* [Bug c++/98995] [11 Regression] Copy elision not applied to members declared with [[no_unique_address]]
  2021-02-08  0:53 [Bug c++/98995] New: Copy elision not applied to members declared with [[no_unique_address]] david at doublewise dot net
@ 2021-02-08  9:36 ` rguenth at gcc dot gnu.org
  2021-02-08 12:15 ` redi at gcc dot gnu.org
                   ` (13 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-02-08  9:36 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |rejects-valid
            Summary|Copy elision not applied to |[11 Regression] Copy
                   |members declared with       |elision not applied to
                   |[[no_unique_address]]       |members declared with
                   |                            |[[no_unique_address]]
   Target Milestone|---                         |11.0

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

* [Bug c++/98995] [11 Regression] Copy elision not applied to members declared with [[no_unique_address]]
  2021-02-08  0:53 [Bug c++/98995] New: Copy elision not applied to members declared with [[no_unique_address]] david at doublewise dot net
  2021-02-08  9:36 ` [Bug c++/98995] [11 Regression] " rguenth at gcc dot gnu.org
@ 2021-02-08 12:15 ` redi at gcc dot gnu.org
  2021-02-08 20:37 ` jason at gcc dot gnu.org
                   ` (12 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: redi at gcc dot gnu.org @ 2021-02-08 12:15 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jason at gcc dot gnu.org

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Started with r11-2704:

    c++: Copy elision and [[no_unique_address]]. [PR93711]

    We don't elide a copy from a function returning a class by value into a
base
    because that can overwrite data laid out in the tail padding of the base
    class; we need to handle [[no_unique_address]] fields the same way, or we
    ICE when the middle-end wants to create a temporary object of a
    TYPE_NEEDS_CONSTRUCTING type.

    This means that we can't always express initialization of a field with
    INIT_EXPR from a TARGET_EXPR the way we usually do, so I needed
    to change several places that were assuming that was sufficient.

    This also fixes 90254, the same problem with C++17 aggregate initialization
    of a base.

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

* [Bug c++/98995] [11 Regression] Copy elision not applied to members declared with [[no_unique_address]]
  2021-02-08  0:53 [Bug c++/98995] New: Copy elision not applied to members declared with [[no_unique_address]] david at doublewise dot net
  2021-02-08  9:36 ` [Bug c++/98995] [11 Regression] " rguenth at gcc dot gnu.org
  2021-02-08 12:15 ` redi at gcc dot gnu.org
@ 2021-02-08 20:37 ` jason at gcc dot gnu.org
  2021-04-27 11:40 ` [Bug c++/98995] [11/12 " jakub at gcc dot gnu.org
                   ` (11 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: jason at gcc dot gnu.org @ 2021-02-08 20:37 UTC (permalink / raw)
  To: gcc-bugs

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

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2021-02-08
             Status|UNCONFIRMED                 |SUSPENDED
     Ever confirmed|0                           |1

--- Comment #2 from Jason Merrill <jason at gcc dot gnu.org> ---
This was a deliberate change.  This language/ABI issue is tracked at
https://wg21.link/cwg2403 and
https://github.com/itanium-cxx-abi/cxx-abi/issues/107

The problem is that we can't safely initialize a base or
potentially-overlapping member from the result of a function call, at least
without a major ABI break, because it might clobber other data allocated into
the tail padding.

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

* [Bug c++/98995] [11/12 Regression] Copy elision not applied to members declared with [[no_unique_address]]
  2021-02-08  0:53 [Bug c++/98995] New: Copy elision not applied to members declared with [[no_unique_address]] david at doublewise dot net
                   ` (2 preceding siblings ...)
  2021-02-08 20:37 ` jason at gcc dot gnu.org
@ 2021-04-27 11:40 ` jakub at gcc dot gnu.org
  2021-07-28  7:05 ` rguenth at gcc dot gnu.org
                   ` (10 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-04-27 11:40 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|11.0                        |11.2

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
GCC 11.1 has been released, retargeting bugs to GCC 11.2.

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

* [Bug c++/98995] [11/12 Regression] Copy elision not applied to members declared with [[no_unique_address]]
  2021-02-08  0:53 [Bug c++/98995] New: Copy elision not applied to members declared with [[no_unique_address]] david at doublewise dot net
                   ` (3 preceding siblings ...)
  2021-04-27 11:40 ` [Bug c++/98995] [11/12 " jakub at gcc dot gnu.org
@ 2021-07-28  7:05 ` rguenth at gcc dot gnu.org
  2022-04-21  7:48 ` rguenth at gcc dot gnu.org
                   ` (9 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-07-28  7:05 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|11.2                        |11.3

--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 11.2 is being released, retargeting bugs to GCC 11.3

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

* [Bug c++/98995] [11/12 Regression] Copy elision not applied to members declared with [[no_unique_address]]
  2021-02-08  0:53 [Bug c++/98995] New: Copy elision not applied to members declared with [[no_unique_address]] david at doublewise dot net
                   ` (4 preceding siblings ...)
  2021-07-28  7:05 ` rguenth at gcc dot gnu.org
@ 2022-04-21  7:48 ` rguenth at gcc dot gnu.org
  2022-04-28 15:12 ` [Bug c++/98995] [11/12/13 " davidfromonline at gmail dot com
                   ` (8 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-04-21  7:48 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|11.3                        |11.4

--- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 11.3 is being released, retargeting bugs to GCC 11.4.

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

* [Bug c++/98995] [11/12/13 Regression] Copy elision not applied to members declared with [[no_unique_address]]
  2021-02-08  0:53 [Bug c++/98995] New: Copy elision not applied to members declared with [[no_unique_address]] david at doublewise dot net
                   ` (5 preceding siblings ...)
  2022-04-21  7:48 ` rguenth at gcc dot gnu.org
@ 2022-04-28 15:12 ` davidfromonline at gmail dot com
  2023-01-08  6:45 ` pinskia at gcc dot gnu.org
                   ` (7 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: davidfromonline at gmail dot com @ 2022-04-28 15:12 UTC (permalink / raw)
  To: gcc-bugs

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

David Stone <davidfromonline at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |davidfromonline at gmail dot com

--- Comment #6 from David Stone <davidfromonline at gmail dot com> ---
Until we get that ABI break, it would be nice if the error message explained
why this doesn't work.

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

* [Bug c++/98995] [11/12/13 Regression] Copy elision not applied to members declared with [[no_unique_address]]
  2021-02-08  0:53 [Bug c++/98995] New: Copy elision not applied to members declared with [[no_unique_address]] david at doublewise dot net
                   ` (6 preceding siblings ...)
  2022-04-28 15:12 ` [Bug c++/98995] [11/12/13 " davidfromonline at gmail dot com
@ 2023-01-08  6:45 ` pinskia at gcc dot gnu.org
  2023-01-08  6:46 ` [Bug c++/98995] [10/11/12/13 " pinskia at gcc dot gnu.org
                   ` (6 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-01-08  6:45 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |yronglin777 at gmail dot com

--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 108333 has been marked as a duplicate of this bug. ***

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

* [Bug c++/98995] [10/11/12/13 Regression] Copy elision not applied to members declared with [[no_unique_address]]
  2021-02-08  0:53 [Bug c++/98995] New: Copy elision not applied to members declared with [[no_unique_address]] david at doublewise dot net
                   ` (7 preceding siblings ...)
  2023-01-08  6:45 ` pinskia at gcc dot gnu.org
@ 2023-01-08  6:46 ` pinskia at gcc dot gnu.org
  2023-01-10 21:35 ` [Bug c++/98995] [10/11/12/13 Regression] Copy elision not applied to members declared with [[no_unique_address]] or a empty base class pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-01-08  6:46 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|11.4                        |10.5
            Summary|[11/12/13 Regression] Copy  |[10/11/12/13 Regression]
                   |elision not applied to      |Copy elision not applied to
                   |members declared with       |members declared with
                   |[[no_unique_address]]       |[[no_unique_address]]

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

* [Bug c++/98995] [10/11/12/13 Regression] Copy elision not applied to members declared with [[no_unique_address]] or a empty base class
  2021-02-08  0:53 [Bug c++/98995] New: Copy elision not applied to members declared with [[no_unique_address]] david at doublewise dot net
                   ` (8 preceding siblings ...)
  2023-01-08  6:46 ` [Bug c++/98995] [10/11/12/13 " pinskia at gcc dot gnu.org
@ 2023-01-10 21:35 ` pinskia at gcc dot gnu.org
  2023-02-06 14:20 ` redi at gcc dot gnu.org
                   ` (4 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-01-10 21:35 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |fchelnokov at gmail dot com

--- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 108364 has been marked as a duplicate of this bug. ***

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

* [Bug c++/98995] [10/11/12/13 Regression] Copy elision not applied to members declared with [[no_unique_address]] or a empty base class
  2021-02-08  0:53 [Bug c++/98995] New: Copy elision not applied to members declared with [[no_unique_address]] david at doublewise dot net
                   ` (9 preceding siblings ...)
  2023-01-10 21:35 ` [Bug c++/98995] [10/11/12/13 Regression] Copy elision not applied to members declared with [[no_unique_address]] or a empty base class pinskia at gcc dot gnu.org
@ 2023-02-06 14:20 ` redi at gcc dot gnu.org
  2023-02-13 16:12 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: redi at gcc dot gnu.org @ 2023-02-06 14:20 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |davidledger at live dot com.au

--- Comment #9 from Jonathan Wakely <redi at gcc dot gnu.org> ---
*** Bug 108683 has been marked as a duplicate of this bug. ***

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

* [Bug c++/98995] [10/11/12/13 Regression] Copy elision not applied to members declared with [[no_unique_address]] or a empty base class
  2021-02-08  0:53 [Bug c++/98995] New: Copy elision not applied to members declared with [[no_unique_address]] david at doublewise dot net
                   ` (10 preceding siblings ...)
  2023-02-06 14:20 ` redi at gcc dot gnu.org
@ 2023-02-13 16:12 ` pinskia at gcc dot gnu.org
  2023-06-30 20:09 ` [Bug c++/98995] [10/11/12/13/14 " pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-02-13 16:12 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |for.gcc.bugzilla at gmail dot com

--- Comment #10 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 82113 has been marked as a duplicate of this bug. ***

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

* [Bug c++/98995] [10/11/12/13/14 Regression] Copy elision not applied to members declared with [[no_unique_address]] or a empty base class
  2021-02-08  0:53 [Bug c++/98995] New: Copy elision not applied to members declared with [[no_unique_address]] david at doublewise dot net
                   ` (11 preceding siblings ...)
  2023-02-13 16:12 ` pinskia at gcc dot gnu.org
@ 2023-06-30 20:09 ` pinskia at gcc dot gnu.org
  2023-07-07 10:39 ` [Bug c++/98995] [11/12/13/14 " rguenth at gcc dot gnu.org
  2023-10-27 13:55 ` jan.kokemueller at gmail dot com
  14 siblings, 0 replies; 16+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-06-30 20:09 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |eric.niebler at gmail dot com

--- Comment #11 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 110507 has been marked as a duplicate of this bug. ***

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

* [Bug c++/98995] [11/12/13/14 Regression] Copy elision not applied to members declared with [[no_unique_address]] or a empty base class
  2021-02-08  0:53 [Bug c++/98995] New: Copy elision not applied to members declared with [[no_unique_address]] david at doublewise dot net
                   ` (12 preceding siblings ...)
  2023-06-30 20:09 ` [Bug c++/98995] [10/11/12/13/14 " pinskia at gcc dot gnu.org
@ 2023-07-07 10:39 ` rguenth at gcc dot gnu.org
  2023-10-27 13:55 ` jan.kokemueller at gmail dot com
  14 siblings, 0 replies; 16+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-07-07 10:39 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|10.5                        |11.5

--- Comment #12 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 10 branch is being closed.

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

* [Bug c++/98995] [11/12/13/14 Regression] Copy elision not applied to members declared with [[no_unique_address]] or a empty base class
  2021-02-08  0:53 [Bug c++/98995] New: Copy elision not applied to members declared with [[no_unique_address]] david at doublewise dot net
                   ` (13 preceding siblings ...)
  2023-07-07 10:39 ` [Bug c++/98995] [11/12/13/14 " rguenth at gcc dot gnu.org
@ 2023-10-27 13:55 ` jan.kokemueller at gmail dot com
  14 siblings, 0 replies; 16+ messages in thread
From: jan.kokemueller at gmail dot com @ 2023-10-27 13:55 UTC (permalink / raw)
  To: gcc-bugs

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

Jan Kokemüller <jan.kokemueller at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jan.kokemueller at gmail dot com

--- Comment #13 from Jan Kokemüller <jan.kokemueller at gmail dot com> ---
Sometimes, all of the padding bytes of a "[[no_unique_address]]" member are
known when designing a class. It would be great if there was a way to say:
"hey, it's OK to do guaranteed copy elision here". Example:

union U {
  [[no_unique_address]] Val val;
  [[no_unique_address]] Err err;
};

struct R {
  [[no_unique_address]] U union;
  [[no_unique_address]] bool has_val;
};

struct expected {
  R r;
};

In this example, "union U" and "struct R" are only used in the "struct
expected", by design. So it should be safe to allow guaranteed copy elision
when initializing the members "val" and "err" of the union since we have full
control over the tail padding bytes (there can only be "has_val" in there,
nothing else).

Maybe there could be an attribute, something like
"[[gnu::allow_guaranteed_copy_elision]]" or
"[[gnu::defer_temporary_materialization]]", to mark those members where
guaranteed copy elision is safe? So you could have:

union U {
  [[no_unique_address,gnu::defer_temporary_materialization]] Val val;
  [[no_unique_address,gnu::defer_temporary_materialization]] Err err;
};

What do you think?

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

end of thread, other threads:[~2023-10-27 13:55 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-08  0:53 [Bug c++/98995] New: Copy elision not applied to members declared with [[no_unique_address]] david at doublewise dot net
2021-02-08  9:36 ` [Bug c++/98995] [11 Regression] " rguenth at gcc dot gnu.org
2021-02-08 12:15 ` redi at gcc dot gnu.org
2021-02-08 20:37 ` jason at gcc dot gnu.org
2021-04-27 11:40 ` [Bug c++/98995] [11/12 " jakub at gcc dot gnu.org
2021-07-28  7:05 ` rguenth at gcc dot gnu.org
2022-04-21  7:48 ` rguenth at gcc dot gnu.org
2022-04-28 15:12 ` [Bug c++/98995] [11/12/13 " davidfromonline at gmail dot com
2023-01-08  6:45 ` pinskia at gcc dot gnu.org
2023-01-08  6:46 ` [Bug c++/98995] [10/11/12/13 " pinskia at gcc dot gnu.org
2023-01-10 21:35 ` [Bug c++/98995] [10/11/12/13 Regression] Copy elision not applied to members declared with [[no_unique_address]] or a empty base class pinskia at gcc dot gnu.org
2023-02-06 14:20 ` redi at gcc dot gnu.org
2023-02-13 16:12 ` pinskia at gcc dot gnu.org
2023-06-30 20:09 ` [Bug c++/98995] [10/11/12/13/14 " pinskia at gcc dot gnu.org
2023-07-07 10:39 ` [Bug c++/98995] [11/12/13/14 " rguenth at gcc dot gnu.org
2023-10-27 13:55 ` jan.kokemueller at gmail dot com

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).