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

Reply via email to