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

--- Comment #26 from Tomasz KamiƄski <tkaminsk at gcc dot gnu.org> ---
The patches above, remove the start_lifetime call out of the _M_init function.
This helps following two cases (https://compiler-explorer.com/z/4cbcjc16o):

std::inplace_vector<char, 4> g() {
  constexpr std::inplace_vector<char, 4> result{'a', 'b', 'c'};
  return result;
}

std::inplace_vector<char, 4> h() {
  constexpr std::array elements{'a', 'b', 'c'};
  return { std::from_range, elements };
}

The g and h above are optimized to by both GCC and clang:
        movabs  rax, 12891415137
        ret

However, the for the function f from original example:
std::inplace_vector<char, 4> f() {
  return {'a', 'b', 'c'};
}

clang emits the same code as for g/h, but GCC still produes:
"f()":
        movzx   eax, WORD PTR "C.0.0"[rip]
        mov     DWORD PTR [rsp-10], 0
        movabs  rdx, 12884901888
        mov     WORD PTR [rsp-10], ax
        movzx   eax, BYTE PTR "C.0.0"[rip+2]
        mov     BYTE PTR [rsp-8], al
        mov     eax, DWORD PTR [rsp-10]
        add     rax, rdx
        ret

Reply via email to