Skip to content

<future>: promise<_Ty&>::set_value(_Ty& _Val) should use _STD addressof(_Val) #272

@StephanTLavavej

Description

@StephanTLavavej

STL/stl/inc/future

Lines 1240 to 1246 in f9b1dcc

void set_value(_Ty& _Val) {
_MyPromise._Get_state_for_set()._Set_value(&_Val, false);
}
void set_value_at_thread_exit(_Ty& _Val) {
_MyPromise._Get_state_for_set()._Set_value(&_Val, true);
}

This code is saying &_Val to get the address of an object (specifically, a parameter passed by reference). This is, perhaps surprisingly, a bug. The STL is required to be extremely flexible and work with near-arbitrary user-defined types. In particular, user-defined types might overload the address-of operator, operator&(), and the STL is required to tolerate this.

We do so by calling the library function addressof(), which uses special magic to get the true address of an object without interference from overloaded operators.

Additionally, the STL is required to defend itself against Argument-Dependent Lookup, so we explicitly qualify all non-_Ugly function calls. We use an internal macro for this: _STD expands to ::std:: .

This should be a two-line fix (unless I have missed other occurrences; note that it is okay to say &thing for object types that can't depend on user-defined types - there's no way that &some_int can misbehave).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixedSomething works now, yay!good first issueGood for newcomers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions