<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/122441>122441</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            std::barrier constructor is not constexpr
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          jwakely
      </td>
    </tr>
</table>

<pre>
    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 https://github.com/llvm/llvm-project/blob/3def49cb64ec1298290724081bd37dbdeb2ea5f8/libcxx/test/tools/clang_tidy_checks/internal_ftm_use.cpp#L29-L30

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:

https://github.com/llvm/llvm-project/blob/3def49cb64ec1298290724081bd37dbdeb2ea5f8/libcxx/src/barrier.cpp#L28-L29

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

Yay.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy8VE1v4zYQ_TX0ZRBDGtr6OOjgfAgNELSL7F56EihyZHGXIgV-xHF_fUHHm2y77aGXnghwqNF7b94bEYI-WqKO7W_Z_n4jUpyd776exDcy583o1Ln7TARzjGtg_MCwZ9gfpdwebdo6f2TYj-n4hzZGMOzD7E7DmI5bedSM91oxfl-WDW_3cJrJE8RZBziJAJP2IYKn1flIasuKAysODy_kz3HW9ggjGXcCZ80ZxLoaTSF3sMCqYnh6vL379Gn45fB5-PW34cvzw8Nwe3h-fnx4ZlUBOkCyiiZtSTG8gzFFiLOIEIiWANHBSCDMSZwDRJ-I8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