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

            Bug ID: 125772
           Summary: Function call not getting inlined for ptr to member
                    function
           Product: gcc
           Version: 15.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: elias.oezcan at sap dot com
                CC: aaron.puchert at sap dot com
  Target Milestone: ---

The following code:

#include <algorithm>

struct S {
    int a;
    bool cond() const noexcept { return a >= 4;}
};

bool foo(const S* s, size_t l) {
    return std::none_of(s, s + l,
    [c = &S::cond](const S& x) {
        return (x.*c)();
    });
}

compiles with -O2 to (x86-64 gcc 15.2):

S::cond() const:
        cmp     DWORD PTR [rdi], 3
        setg    al
        ret
foo(S const*, unsigned long):
        push    r12
        push    rbp
        lea     rbp, [rdi+rsi*4]
        push    rbx
        mov     rbx, rdi
        cmp     rbp, rdi
        je      .L4
        mov     rax, rbp
        sub     rax, rdi
        sub     rax, 4
        shr     rax, 2
        add     rax, 1
        and     eax, 3
        je      .L5
        cmp     rax, 1
        je      .L16
        cmp     rax, 2
        je      .L17
        call    S::cond() const
        test    al, al
        jne     .L4
 ...

The original function, that surfaced this looked like this:

bool foo(const S* s, size_t l) {
    return std::none_of(s, s + l, std::mem_fn(&S::isErrorOrWorse));
}


I don't see why the function call can't be inlined. The call doesn't seem to
get inlined for any x86-64 gcc compiler.

Reply via email to