Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lambda converted function pointer comparison

Simply, will the following assert ever fire?

template<typename T>
auto destructor()
{
    return +[](void* p){
        ((T*)p)->~T();
    };
}

assert(destructor<int>() != destructor<char>());

The standard only seems to say that the lambda converted function pointer does the same thing as the lambda itself, then you realize trivially destructed types all have no-op destructors and are therefore identical.

like image 678
Passer By Avatar asked Jan 28 '18 10:01

Passer By


1 Answers

[expr.prim.lambda]/6:

The value returned by this conversion function is the address of a function F that, when invoked, has the same effect as invoking the closure type's function call operator.

The pointed to function is specified in term of its behavior, not in term of its identity. So it is unspecified if this assertion will fire.

like image 183
Oliv Avatar answered Nov 14 '22 08:11

Oliv