Passer By
Passer By

Reputation: 21131

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.

Upvotes: 8

Views: 154

Answers (1)

Oliv
Oliv

Reputation: 18051

[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.

Upvotes: 4

Related Questions