public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/106094] New: Lifetime extension of temporary do not obey some rules of [class.temporary]
@ 2022-06-26 21:41 kirshamir at gmail dot com
  2022-06-26 21:49 ` [Bug c++/106094] " pinskia at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: kirshamir at gmail dot com @ 2022-06-26 21:41 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 106094
           Summary: Lifetime extension of temporary do not obey some rules
                    of [class.temporary]
           Product: gcc
           Version: 12.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kirshamir at gmail dot com
  Target Milestone: ---

The simple cases of lifetime extension are working.

But all below do not obey the rules.
Lifetime should have been extended and it is not.

    // casting (non user-defined) + member access
    const auto& a1 = static_cast<const A&&>(A("a1")).ptr;

    // casting (non user-defined) + member access
    const auto& a2 = ((const A&&)A("a2")).arr;

    // casting (non user-defined) + member access
    const auto& a3 = const_cast<const A&&>(A("a3")).str;

    // a pointer to a member + extending lifetime access
    const auto& arr_member = &A::arr;
    const auto& a4 = (A("a4").*arr_member)[0];

    const auto& str_member = &A::str;
    const auto& a5 = A("a5").*str_member;

    const auto& ptr_member = &A::ptr;
    const auto& a6 = A("a6").*ptr_member;

Code:
https://godbolt.org/z/jeeoefhPr

Rules:
https://timsong-cpp.github.io/cppwp/n4868/class.temporary#6

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

* [Bug c++/106094] Lifetime extension of temporary do not obey some rules of [class.temporary]
  2022-06-26 21:41 [Bug c++/106094] New: Lifetime extension of temporary do not obey some rules of [class.temporary] kirshamir at gmail dot com
@ 2022-06-26 21:49 ` pinskia at gcc dot gnu.org
  2022-06-26 21:50 ` pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-06-26 21:49 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=101572

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
dynamic cast is filed as PR 101572 (though I don't see a test here).

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

* [Bug c++/106094] Lifetime extension of temporary do not obey some rules of [class.temporary]
  2022-06-26 21:41 [Bug c++/106094] New: Lifetime extension of temporary do not obey some rules of [class.temporary] kirshamir at gmail dot com
  2022-06-26 21:49 ` [Bug c++/106094] " pinskia at gcc dot gnu.org
@ 2022-06-26 21:50 ` pinskia at gcc dot gnu.org
  2022-06-26 21:50 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-06-26 21:50 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Created attachment 53203
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53203&action=edit
testcase

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

* [Bug c++/106094] Lifetime extension of temporary do not obey some rules of [class.temporary]
  2022-06-26 21:41 [Bug c++/106094] New: Lifetime extension of temporary do not obey some rules of [class.temporary] kirshamir at gmail dot com
  2022-06-26 21:49 ` [Bug c++/106094] " pinskia at gcc dot gnu.org
  2022-06-26 21:50 ` pinskia at gcc dot gnu.org
@ 2022-06-26 21:50 ` pinskia at gcc dot gnu.org
  2022-06-26 21:52 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-06-26 21:50 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Also please attach the testcase next time rather than just a link to godbolt. I
attached it this time.

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

* [Bug c++/106094] Lifetime extension of temporary do not obey some rules of [class.temporary]
  2022-06-26 21:41 [Bug c++/106094] New: Lifetime extension of temporary do not obey some rules of [class.temporary] kirshamir at gmail dot com
                   ` (2 preceding siblings ...)
  2022-06-26 21:50 ` pinskia at gcc dot gnu.org
@ 2022-06-26 21:52 ` pinskia at gcc dot gnu.org
  2023-08-11 20:36 ` jason at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-06-26 21:52 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Depends on|                            |53288

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
PR 53288 is for the pointer to a member case I think.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53288
[Bug 53288] [C++11] Lifetime of temporary object backing pointer-to-member
expression not extended

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

* [Bug c++/106094] Lifetime extension of temporary do not obey some rules of [class.temporary]
  2022-06-26 21:41 [Bug c++/106094] New: Lifetime extension of temporary do not obey some rules of [class.temporary] kirshamir at gmail dot com
                   ` (3 preceding siblings ...)
  2022-06-26 21:52 ` pinskia at gcc dot gnu.org
@ 2023-08-11 20:36 ` jason at gcc dot gnu.org
  2023-08-11 20:42 ` jason at gcc dot gnu.org
  2023-08-12  1:19 ` de34 at live dot cn
  6 siblings, 0 replies; 8+ messages in thread
From: jason at gcc dot gnu.org @ 2023-08-11 20:36 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106094
Bug 106094 depends on bug 53288, which changed state.

Bug 53288 Summary: [C++11] Lifetime of temporary object backing pointer-to-member expression not extended
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53288

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

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

* [Bug c++/106094] Lifetime extension of temporary do not obey some rules of [class.temporary]
  2022-06-26 21:41 [Bug c++/106094] New: Lifetime extension of temporary do not obey some rules of [class.temporary] kirshamir at gmail dot com
                   ` (4 preceding siblings ...)
  2023-08-11 20:36 ` jason at gcc dot gnu.org
@ 2023-08-11 20:42 ` jason at gcc dot gnu.org
  2023-08-12  1:19 ` de34 at live dot cn
  6 siblings, 0 replies; 8+ messages in thread
From: jason at gcc dot gnu.org @ 2023-08-11 20:42 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code
             Status|UNCONFIRMED                 |NEW
                 CC|                            |jason at gcc dot gnu.org
   Last reconfirmed|                            |2023-08-11
     Ever confirmed|0                           |1

--- Comment #5 from Jason Merrill <jason at gcc dot gnu.org> ---
Confirmed.

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

* [Bug c++/106094] Lifetime extension of temporary do not obey some rules of [class.temporary]
  2022-06-26 21:41 [Bug c++/106094] New: Lifetime extension of temporary do not obey some rules of [class.temporary] kirshamir at gmail dot com
                   ` (5 preceding siblings ...)
  2023-08-11 20:42 ` jason at gcc dot gnu.org
@ 2023-08-12  1:19 ` de34 at live dot cn
  6 siblings, 0 replies; 8+ messages in thread
From: de34 at live dot cn @ 2023-08-12  1:19 UTC (permalink / raw)
  To: gcc-bugs

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

Jiang An <de34 at live dot cn> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |de34 at live dot cn

--- Comment #6 from Jiang An <de34 at live dot cn> ---
CWG2666 may be related.
https://cplusplus.github.io/CWG/issues/2666.html

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

end of thread, other threads:[~2023-08-12  1:19 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-26 21:41 [Bug c++/106094] New: Lifetime extension of temporary do not obey some rules of [class.temporary] kirshamir at gmail dot com
2022-06-26 21:49 ` [Bug c++/106094] " pinskia at gcc dot gnu.org
2022-06-26 21:50 ` pinskia at gcc dot gnu.org
2022-06-26 21:50 ` pinskia at gcc dot gnu.org
2022-06-26 21:52 ` pinskia at gcc dot gnu.org
2023-08-11 20:36 ` jason at gcc dot gnu.org
2023-08-11 20:42 ` jason at gcc dot gnu.org
2023-08-12  1:19 ` de34 at live dot cn

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