Title
"Named" temporaries and copy elision
Status
tc1
Section
11.4.5.3 [class.copy.ctor]
Submitter
Bill Wade

Created on 1999-11-11.00:00:00 last changed 263 months ago

Messages

Date: 2000-04-15.00:00:00

Proposed resolution (10/00):

Change the wording proposed in the resolution of issue 20 from

  • when a temporary class object (6.7.7 [class.temporary]) would be copied to a class object...

to

  • when a temporary class object that has not been bound to a reference (6.7.7 [class.temporary]) would be copied to a class object...
Date: 2022-02-18.07:47:23

11.4.5.3 [class.copy.ctor] paragraph 15 refers only to "temporary class objects." It needs to be made clear that these provisions do not apply to temporaries that have been bound to references. For instance,

    struct A {
        mutable int value;
        explicit A(int i) : value(i) {}
        void mutate(int i) const { value = i; }
    };

    int foo() {
        A const& t = A(1);
        A n(t);          // can this copy be elided?
        t.mutate(2);
        return n.value;  // can this return 2?
    }
The current wording seems to allow an implementation not to perform the copy in A N(t) because the source object is a temporary (created explicitly by A(1)).
History
Date User Action Args
2003-04-25 00:00:00adminsetstatus: dr -> tc1
2000-11-18 00:00:00adminsetstatus: ready -> dr
2000-05-21 00:00:00adminsetmessages: + msg316
2000-05-21 00:00:00adminsetstatus: open -> ready
1999-11-11 00:00:00admincreate