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

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