public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/114940] New: std::generator relies on an optional overload of operator delete
@ 2024-05-03 19:39 liuxf19 at 163 dot com
  2024-05-03 19:56 ` [Bug libstdc++/114940] " liuxf19 at 163 dot com
                   ` (12 more replies)
  0 siblings, 13 replies; 14+ messages in thread
From: liuxf19 at 163 dot com @ 2024-05-03 19:39 UTC (permalink / raw)
  To: gcc-bugs

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++.

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2024-05-28 11:09 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-03 19:39 [Bug libstdc++/114940] New: std::generator relies on an optional overload of operator delete liuxf19 at 163 dot com
2024-05-03 19:56 ` [Bug libstdc++/114940] " liuxf19 at 163 dot com
2024-05-03 19:57 ` redi at gcc dot gnu.org
2024-05-03 19:57 ` redi at gcc dot gnu.org
2024-05-03 20:08 ` liuxf19 at 163 dot com
2024-05-04  8:47 ` arsen at gcc dot gnu.org
2024-05-04 11:02 ` redi at gcc dot gnu.org
2024-05-04 12:10 ` arsen at gcc dot gnu.org
2024-05-22  9:30 ` redi at gcc dot gnu.org
2024-05-22  9:37 ` redi at gcc dot gnu.org
2024-05-22 22:30 ` cvs-commit at gcc dot gnu.org
2024-05-28  9:20 ` cvs-commit at gcc dot gnu.org
2024-05-28 11:08 ` cvs-commit at gcc dot gnu.org
2024-05-28 11:09 ` redi at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).