[cxx-abi-dev] The magic of uncalled copy constructors; documenting the bug

Richard Smith richardsmith at google.com
Sat Feb 8 22:39:21 UTC 2014


On 8 February 2014 12:43, Hubert Tong <hstong at ca.ibm.com> wrote:

> Hi all,
>
> I think this has been visited every once in a while with regards to the
> addition of move constructors, defaulted and deleted constructors, etc.
> The following case magically works thanks to a pair of copy constructors
> which are never used by the program, and breaks otherwise because of an
> issue with the calling conventions.
>
> As a consumer of the ABI document, I would appreciate if it mentioned the
> known cases where it is not suitable for a compliant implementation of the
> C++ language.
>
Agreement here and (IIRC) in CWG was that this is a defect in the language
spec, not in the ABI. See core issue 1590.

> Thanks,
>
>
> Hubert Tong
>
> #include <cassert>
>
> class A {
> private:
> #if ! REMOVE_COPY_CTOR
>    A(const A &, void * = 0);
>    A(const A &, bool = 0);
> #endif
>
> public:
>    template <typename T>
>    A(const volatile T &t) : a(t.a), b(a) { }
>
>    A() : a(0), b(a) { }
>
>    long a, &b;
> };
>
> long bar(A a) {
>    ++a.b;
>    return a.a;
> }
>
> int main() {
>    volatile A a;
>    long ret = bar(a);
>    assert(ret == 1);
> }
>
> _______________________________________________
> cxx-abi-dev mailing list
> cxx-abi-dev at codesourcery.com
> http://sourcerytools.com/cgi-bin/mailman/listinfo/cxx-abi-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://sourcerytools.com/pipermail/cxx-abi-dev/attachments/20140208/76878eb8/attachment.html>


More information about the cxx-abi-dev mailing list