public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "liuxf19 at 163 dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/114940] New: std::generator relies on an optional overload of operator delete
Date: Fri, 03 May 2024 19:39:34 +0000	[thread overview]
Message-ID: <bug-114940-4@http.gcc.gnu.org/bugzilla/> (raw)

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

             reply	other threads:[~2024-05-03 19:39 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-03 19:39 liuxf19 at 163 dot com [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-114940-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).