Skip to content

"Wrong" name mangling for operator== in extern "C" #140654

@Alcaro

Description

@Alcaro
struct mytype {};

extern "C" {
bool operator==(const mytype & a, const mytype & b);
}

bool foo(const mytype & a)
{
 return a == a;
}

Clang:

_Z3fooRK6mytype:
        mov     rsi, rdi
        jmp     _ZeqRK6mytypeS1_@PLT

GCC:

_Z3fooRK6mytype:
        mov     rsi, rdi
        jmp     _Zeq

I don't particularly care which name is used, but you're supposed to match GCC, right? (Or is GCC the one that's wrong? I'll file this against them instead if you prefer that.)

https://godbolt.org/z/xhh7T7KGd

https://eel.is/c++draft/over.literal#6 bans extern "C" for user defined literals, and such language is absent on other operators, so I think extern "C" must be tolerated on other opeerators. But they should probably be a warning.

(Originally found in mingw headers https://godbolt.org/z/xx4EP9bxG - they forgot an extern "C++" in guiddef.h.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:codegenIR generation bugs: mangling, exceptions, etc.diverges-from:edgDoes the clang frontend diverge from edg compiler on this issuediverges-from:gccDoes the clang frontend diverge from gcc on this issuediverges-from:msvcDoes the clang frontend diverge from msvc on this issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions