Skip to content

std::barrier constructor is not constexpr #122441

@jwakely

Description

@jwakely

See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118395 where this was first reported.

Everything below only applies when _LIBCPP_HAS_NO_TREE_BARRIER is undefined, but that seems to be always true? I'm not sure, see

// TODO: Why does this macro even exist?
"_LIBCPP_HAS_NO_TREE_BARRIER",

The std::barrier(ptrdiff_t, CompletionFunction) is supposed to be constexpr. It can't be, because it calls a non-inline function which allocates memory.

Also std::barrier<>(std::barrier<>::max()) should be valid, but max() just returns numeric_limits<ptrdiff_t>::max() and then the non-inline allocating function does:

size_t const __count = (__expected + 1) >> 1;
__state_ = unique_ptr<__state_t[]>(new __state_t[__count]);

so if __expected == max() then __expected + 1 overflows, with undefined behaviour.

Yay.

Metadata

Metadata

Assignees

No one assigned

    Labels

    libc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions