Skip to content

<algorithm>: debug checks for predicates are observable #1006

Description

Describe the bug
Debug version std::min_element assumes that the range is not modified while working on it.

It triggers the following check:

STL/stl/inc/xutility

Lines 1589 to 1598 in 5be7d49

constexpr bool _Debug_lt_pred(_Pr&& _Pred, _Ty1&& _Left, _Ty2&& _Right) noexcept(
noexcept(_Pred(_Left, _Right)) && noexcept(_Pred(_Right, _Left))) {
// test if _Pred(_Left, _Right) and _Pred is strict weak ordering, when the arguments are the cv-same-type
const auto _Result = static_cast<bool>(_Pred(_Left, _Right));
if (_Result) {
_STL_VERIFY(!_Pred(_Right, _Left), "invalid comparator");
}
return _Result;
}

This assertion is triggered when std::min_element is used on array of std::atomic values that are incremented independently by concurrent threads.

DevCom-222276 reporter asks:

Are there any limitations in the standard about std::min_elements() that I should know?

Additional context

  • Skipped libcxx tests:
    # Predicate count assertions - IDL2 is slightly bending the Standard's rules here.
    std/algorithms/alg.sorting/alg.heap.operations/make.heap/make_heap_comp.pass.cpp FAIL
    std/algorithms/alg.sorting/alg.merge/inplace_merge_comp.pass.cpp FAIL
    std/algorithms/alg.sorting/alg.min.max/minmax_init_list_comp.pass.cpp FAIL

Also tracked by DevCom-222276 and Microsoft-internal VSO-592348 / AB#592348.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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