Skip to content

<functional>: move_only_function behaves differently when constructed with null function pointer in slightly different ways #5806

@AlexGuteniev

Description

@AlexGuteniev

The following program:

#include <functional>
#include <print>

int main() {
    std::move_only_function<int(int)> fn1(static_cast<int(*)(int)>(nullptr));
    std::move_only_function<int(int)> fn2(std::in_place_type<int(*)(int)>, nullptr);
    std::print("fn1: {}, fn2: {}", static_cast<bool>(fn1), static_cast<bool>(fn2));
}

Prints:

fn1: false, fn2: true

This is what the Standard is apparently asking for.

Isn't this stupid?

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions