Issue |
125187
|
Summary |
[libc++] Some string functions are broken when the allocator size_type is unsigned char
|
Labels |
libc++,
rejects-valid
|
Assignees |
|
Reporter |
philnik777
|
```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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs