public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/114242] New: Coroutine with lambda-coroutine and operator new does not compile
@ 2024-03-05 15:42 src at andyf dot de
  2024-03-05 18:14 ` [Bug c++/114242] " pinskia at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: src at andyf dot de @ 2024-03-05 15:42 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114242

            Bug ID: 114242
           Summary: Coroutine with lambda-coroutine and operator new does
                    not compile
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: src at andyf dot de
  Target Milestone: ---

Hello,

the following code is accepted by Clang but rejected by g++ and MSVC:

https://compiler-explorer.com/z/7P548dGG3

Once the lambda inside the coroutine isn't used, the code compiles with all
three compilers. 
My reading of http://eel.is/c++draft/dcl.fct.def.coroutine#9.1 is that the
custom operator new should be picked in all cases.

G++'s error:

```
<source>: In lambda function:
<source>:54:15: error: 'operator new' is provided by
'std::__n4861::__coroutine_traits_impl<Generator, void>::promise_type' {aka
'Generator::promise_type'} but is not usable with the function signature
'coro(std::span<unsigned char>)::<lambda(std::span<unsigned char>)>'
   54 |   auto lamb = [](std::span<unsigned char>) -> Generator {
      |               ^
```

suggests that the compiler tries to look up an operator new with only size as
an argument.

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

* [Bug c++/114242] Coroutine with lambda-coroutine and operator new does not compile
  2024-03-05 15:42 [Bug c++/114242] New: Coroutine with lambda-coroutine and operator new does not compile src at andyf dot de
@ 2024-03-05 18:14 ` pinskia at gcc dot gnu.org
  2024-03-05 18:15 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-05 18:14 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114242

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note IIRC C++26 (maybe even 23) changed in this area over C++20 and GCC is
following (the initial?) C++20 rules.

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

* [Bug c++/114242] Coroutine with lambda-coroutine and operator new does not compile
  2024-03-05 15:42 [Bug c++/114242] New: Coroutine with lambda-coroutine and operator new does not compile src at andyf dot de
  2024-03-05 18:14 ` [Bug c++/114242] " pinskia at gcc dot gnu.org
@ 2024-03-05 18:15 ` pinskia at gcc dot gnu.org
  2024-03-05 18:20 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-05 18:15 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114242

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Created attachment 57617
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57617&action=edit
testcase

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

* [Bug c++/114242] Coroutine with lambda-coroutine and operator new does not compile
  2024-03-05 15:42 [Bug c++/114242] New: Coroutine with lambda-coroutine and operator new does not compile src at andyf dot de
  2024-03-05 18:14 ` [Bug c++/114242] " pinskia at gcc dot gnu.org
  2024-03-05 18:15 ` pinskia at gcc dot gnu.org
@ 2024-03-05 18:20 ` pinskia at gcc dot gnu.org
  2024-03-05 18:46 ` src at andyf dot de
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-05 18:20 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114242

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |C++-coroutines,
                   |                            |rejects-valid
              Alias|                            |cwg2585
             Blocks|                            |94404

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Yes it looks like GCC does not implement CWG 2585.
https://cplusplus.github.io/CWG/issues/2585.html


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94404
[Bug 94404] [meta-bug] C++ core issues

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

* [Bug c++/114242] Coroutine with lambda-coroutine and operator new does not compile
  2024-03-05 15:42 [Bug c++/114242] New: Coroutine with lambda-coroutine and operator new does not compile src at andyf dot de
                   ` (2 preceding siblings ...)
  2024-03-05 18:20 ` pinskia at gcc dot gnu.org
@ 2024-03-05 18:46 ` src at andyf dot de
  2024-03-05 19:51 ` src at andyf dot de
  2024-03-08 17:21 ` src at andyf dot de
  5 siblings, 0 replies; 7+ messages in thread
From: src at andyf dot de @ 2024-03-05 18:46 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114242

--- Comment #4 from Andreas Fertig <src at andyf dot de> ---
Thanks for looking into the issue!

While CWG 2585 tweaks the wording, my reading is that the code should be valid
even with C++20.

Regardless of that, without the lambda, the code compiles and uses a custom
allocator. 

After playing with the test case, I could reduce it to having only a
coroutine-lambda with a promise_type that has a custom operator new:

https://compiler-explorer.com/z/W53nKsfxG

Sorry for not having that done initially!

I suspect this case wasn't implemented (because it isn't obvious?).

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

* [Bug c++/114242] Coroutine with lambda-coroutine and operator new does not compile
  2024-03-05 15:42 [Bug c++/114242] New: Coroutine with lambda-coroutine and operator new does not compile src at andyf dot de
                   ` (3 preceding siblings ...)
  2024-03-05 18:46 ` src at andyf dot de
@ 2024-03-05 19:51 ` src at andyf dot de
  2024-03-08 17:21 ` src at andyf dot de
  5 siblings, 0 replies; 7+ messages in thread
From: src at andyf dot de @ 2024-03-05 19:51 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114242

--- Comment #5 from Andreas Fertig <src at andyf dot de> ---
My latest conclusion is that my code is indeed invalid. In the case of the
lambda, I have a class type. http://eel.is/c++draft/dcl.fct.def.coroutine#4
says that in such a case, p1 is an lvalue of *this. If I modify my original
example, g++ and MSVC accept the code, but Clang now rejects it:

https://compiler-explorer.com/z/1hhxfYW1v

I will open an issue there and let them confirm. But I think we can close this
issue for g++.

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

* [Bug c++/114242] Coroutine with lambda-coroutine and operator new does not compile
  2024-03-05 15:42 [Bug c++/114242] New: Coroutine with lambda-coroutine and operator new does not compile src at andyf dot de
                   ` (4 preceding siblings ...)
  2024-03-05 19:51 ` src at andyf dot de
@ 2024-03-08 17:21 ` src at andyf dot de
  5 siblings, 0 replies; 7+ messages in thread
From: src at andyf dot de @ 2024-03-08 17:21 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114242

Andreas Fertig <src at andyf dot de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |INVALID
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #6 from Andreas Fertig <src at andyf dot de> ---
The behavior of g++ is correct.

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

end of thread, other threads:[~2024-03-08 17:21 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-05 15:42 [Bug c++/114242] New: Coroutine with lambda-coroutine and operator new does not compile src at andyf dot de
2024-03-05 18:14 ` [Bug c++/114242] " pinskia at gcc dot gnu.org
2024-03-05 18:15 ` pinskia at gcc dot gnu.org
2024-03-05 18:20 ` pinskia at gcc dot gnu.org
2024-03-05 18:46 ` src at andyf dot de
2024-03-05 19:51 ` src at andyf dot de
2024-03-08 17:21 ` src at andyf dot de

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