llvm / llvm/llvm-project

LIBC++, CLANG 15.20, stable_partition() does meet the ISO C++ requirements of only calling the predicate N times for low memory situations

Open
#203,643 1 comment 0 reactions 0 assignees View on GitHub
clang libc++
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

This is an instrumented code investigation into stable_partition. I have tested out Microsoft's, GCC's & CLANG's libraries of stable_partition(). 1 million items are added to a vector, randomly (using a homebrew random generator. This is for 64-bit C++ compilers, all the latest version.

stable_partition() is called with a suitable predicate. Now the ISO C++ requirements is that the predicate is called no more than 1 million times (as many as the number of items beign partitioned). stable_partition() can be run with enough memory for a buffer or without a buffer. Either way, the number of calls to the predicate should not change.

If the code is compiled with NOBUFFER defined => then the replacement operator new, nothrow is in operation and will starve memory being allocated for a buffer. If the code is compiled with NOBUFFER undefined or commented out => then a buffer is allocated.

When run, I see for the 6 situations:

Microsoft, buffered: Compare Count = 1000000
Microsoft, unbuffered: Compare Count = 1000000
GCC, buffered: Compare Count = 1000000
GCC, unbuffered: Compare Count = 1000000
CLANG, buffered: Compare Count = 1000000
CLANG, unbuffered: Compare Count = 1052964

See here for code link:
https://www.linkedin.com/pulse/clangs-stablepartition-1520-fails-iso-c-requirements-under-howe-dqvbe/

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.