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

            Bug ID: 110793
           Summary: regression in optimizing unused string
           Product: gcc
           Version: 13.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: barry.revzin at gmail dot com
  Target Milestone: ---

Consider this reduced, silly-looking example:

#include <string>

inline int zero(std::string const& = {}) { return 0; }

int main() {
    return zero();
}

In several versions of gcc (12.2, 11.4, 10.5), this simply compiles to:

main:
        xor     eax, eax
        ret

But in 13.1 (C++17, but not C++20), we get:

main:
        sub     rsp, 40
        lea     rax, [rsp+16]
        mov     rdi, rsp
        mov     BYTE PTR [rsp+16], 0
        mov     QWORD PTR [rsp], rax
        mov     QWORD PTR [rsp+8], 0
        call    std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> >::_M_dispose()
        xor     eax, eax
        add     rsp, 40
        ret

Notably, 13.1 C++20 and C++23 also compiles to just xor. 

I'm not sure if this is a language or library issue, so tagging it language for
now.

Reply via email to