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

            Bug ID: 111805
           Summary: suboptimal codegen of variant<string, bool>
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hiraditya at msn dot com
  Target Milestone: ---

#include<variant>
#include<string>

std::string foo() {
    std::variant<std::string, bool> v {"abc"};
    return std::get<0>(v);
}

g++-13.2 -O2 -std=c++20


foo[abi:cxx11]():
        lea     rdx, [rdi+16]
        mov     BYTE PTR [rdi+18], 99
        mov     rax, rdi
        mov     QWORD PTR [rdi], rdx
        mov     edx, 25185
        mov     WORD PTR [rdi+16], dx
        mov     QWORD PTR [rdi+8], 3
        mov     BYTE PTR [rdi+19], 0
        ret


clang++ -O2 -std=c++20

foo():                                # @foo()
        mov     rax, rdi
        mov     byte ptr [rdi], 6
        mov     dword ptr [rdi + 1], 6513249
        ret


https://godbolt.org/z/nTv5rYanM

Reply via email to