<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/125187>125187</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[libc++] Some string functions are broken when the allocator size_type is unsigned char
</td>
</tr>
<tr>
<th>Labels</th>
<td>
libc++,
rejects-valid
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
philnik777
</td>
</tr>
</table>
<pre>
```c++
#include <cassert>
#include <cstddef>
#include <memory>
#include <string>
template <std::size_t MaxSize, class T>
struct tiny_size_allocator {
using value_type = T;
using size_type = unsigned char;
template <class U>
struct rebind {
using other = tiny_size_allocator<MaxSize, T>;
};
tiny_size_allocator() = default;
template <class U>
tiny_size_allocator(tiny_size_allocator<MaxSize, U>) {}
T* allocate(std::size_t n) {
assert(n <= MaxSize);
return std::allocator<T>{}.allocate(n);
}
void deallocate(T* ptr, std::size_t n) { std::allocator<T>{}.deallocate(ptr, n); }
size_type max_size() { return MaxSize; }
friend bool operator==(tiny_size_allocator, tiny_size_allocator) { return true; }
friend bool operator!=(tiny_size_allocator, tiny_size_allocator) { return false; }
};
void test() {
std::basic_string<char, std::char_traits<char>, tiny_size_allocator<10, char>> str;
str == "";
}
```
currently fails with
```
/opt/compiler-explorer/clang-trunk-20250131/bin/../include/c++/v1/string:3753:22: error: no matching function for call to 'min'
3753 | size_type __rlen = std::min(__n1, __sz - __pos1);
| ^~~~~~~~
```
We should probably also test other interfaces.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJykVU2PozgQ_TXOpZQITFjgwIFOmtueZlZ7RAaK4G1jI9tkOn3Y376ygTTpzWpWmshSJOrjvVdVLjNj-EUi5iR-IfF5xybbK52PPReSvyVJsqtVe8vJb8F8GkJf3AkKQiMuGzG1CCQ6NcwY1JZEr_82Gdu22D0zDTgofXtmMVZzeVksQWFxGAWzi6klUUGiwvAPrCz8zt6_8Q8k9ASNYMbA9znMWD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