[cfe-dev] Itanium ABI updated regarding returning non-trivially moveable types

Toby Allsopp via cfe-dev cfe-dev at lists.llvm.org
Fri May 26 16:53:14 PDT 2017


This is relevant to https://bugs.llvm.org//show_bug.cgi?id=28593.

See
https://github.com/itanium-cxx-abi/cxx-abi/commit/eacbae1ebd0da58b25ddb57f5abf43efe6ab7cad
.

This means that clang does the wrong thing according to the ABI as well as
the C++ standard for this program:

#include <stdio.h>

struct S {
    int i;
    S(S*& p) { printf("S(): %p\n", this); p = this; }
    S(S const&) = delete;
};

S get_s(S*& p) { return S(p); }

int main() {
    S* p;
    S s = get_s(p);
    printf(" &s: %p\n", &s);
    printf("  p: %p\n", p);
    printf("%s\n", &s == p ? "same" : "different");
}

GCC prints "same". Clang prints "different". I'm actually not sure if that
pointer comparison is defined behaviour or not, but I don't think it
matters here.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170527/d037fc5c/attachment.html>


More information about the cfe-dev mailing list