https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114940
Bug ID: 114940
Summary: std::generator relies on an optional overload of
operator delete
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: liuxf19 at 163 dot com
Target Milestone: ---
The bug report #114891 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114891
discussed the impact of is_pointer_interconvertible_base_of_v on using
std::generator with clang++ and libstdc++. There's another issue when
std::generator in libstdc++ is used by other compilers such as clang++.
In the header <generator>, an overload of operator delete:
void operator delete ( void* ptr, std::size_t sz ) noexcept;
However, this is an OPTIONAL feature whose feature test macro is
__cpp_sized_deallocation macro. Some compilers especially clang++, even the
newest clang trunk (which is avaiable at https://godbolt.org, and the version
is 19.0.0) didn't implement this macro. For example, the code below:
#include <new>
int main() {
#ifndef __cpp_sized_deallocation
static_assert(false, "no __cpp_sized_deallocation");
#endif
}
compiled with: clang++ -std=c++23 -stdlib=libstdc++
will cause the following errors:
<source>:5:19: error: static assertion failed: no __cpp_sized_deallocation
5 | static_assert(false, "no __cpp_sized_deallocation");
| ^~~~~
1 error generated.
ASM generation compiler returned: 1
<source>:5:19: error: static assertion failed: no __cpp_sized_deallocation
5 | static_assert(false, "no __cpp_sized_deallocation");
| ^~~~~
1 error generated.
See https://gcc.godbolt.org/z/MocWxMKz6 for details.
And thus there's no this overload with clang++.
But the std::generator in libstdc++ relies on this overload, which also causes
clang++ cannot use std::generator in libstdc++ (even after clang++ 19 provided
is_pointer_interconvertible_base_of discussed in #114891).
The following code:
#include <new>
#include <generator>
std::generator<int> iota(int n) {
for (int i = 0; i < n; ++i) {
co_yield i;
}
}
int main() {
for (auto i : iota(10)) {
}
return 0;
}
compiled with: clang++ -std=c++23 -stdlib=libstdc++
And the compilation errors:
In file included from main.cpp:16:
/usr/bin/../lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/generator:606:6:
error: no matching function for call to 'operator delete'
606 | ::operator delete(__ptr, _M_alloc_size<void>(__sz));
| ^~~~~~~~~~~~~~~~~
See https://gcc.godbolt.org/z/xjMGaq36a for details.
Note that there's no restrictions that std::generator must depends on this
overload of operator delete in ISO C++. This may cause clang++ or other
compilers cannot use std::generator in libstdc++.