public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/109867] New: -Wswicht-default reports missing default in coroutine
@ 2023-05-15 21:44 lukaslang.bugtracker at outlook dot com
  2024-01-30 14:04 ` [Bug c++/109867] -Wswitch-default " piotrwn1 at gmail dot com
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: lukaslang.bugtracker at outlook dot com @ 2023-05-15 21:44 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 109867
           Summary: -Wswicht-default reports missing default in coroutine
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: lukaslang.bugtracker at outlook dot com
  Target Milestone: ---

Consider the following implementation of a simple coroutine
(https://godbolt.org/z/rcevTd5f6):

#include <coroutine>

struct task
{
    struct promise_type
    {
        std::suspend_always initial_suspend();
        std::suspend_always final_suspend() noexcept;
        void unhandled_exception();
        task get_return_object();
        void return_value(int);
    };
};

int main()
{
    auto t = []() -> task
    {
        co_return 2;
    }();
} 

Compiling this with -std=c++20 -Wswitch-default -Werror results in an error at
the end of the coroutine body:

<source>:20:5: error: switch missing default case [-Werror=switch-default]
   20 |     }();

Since I can get neither clang nor msvc to complain, I assume this is a bug, or
am I missing something? If this is indeed a bug, can I work around this without
having to disable the warning?

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

* [Bug c++/109867] -Wswitch-default reports missing default in coroutine
  2023-05-15 21:44 [Bug c++/109867] New: -Wswicht-default reports missing default in coroutine lukaslang.bugtracker at outlook dot com
@ 2024-01-30 14:04 ` piotrwn1 at gmail dot com
  2024-07-16 19:18 ` arsen at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: piotrwn1 at gmail dot com @ 2024-01-30 14:04 UTC (permalink / raw)
  To: gcc-bugs

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

Piotr Nycz <piotrwn1 at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |piotrwn1 at gmail dot com

--- Comment #1 from Piotr Nycz <piotrwn1 at gmail dot com> ---
This also happens for void coroutine (return_void()).
Quite big annoying

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

* [Bug c++/109867] -Wswitch-default reports missing default in coroutine
  2023-05-15 21:44 [Bug c++/109867] New: -Wswicht-default reports missing default in coroutine lukaslang.bugtracker at outlook dot com
  2024-01-30 14:04 ` [Bug c++/109867] -Wswitch-default " piotrwn1 at gmail dot com
@ 2024-07-16 19:18 ` arsen at gcc dot gnu.org
  2024-07-22 15:07 ` arsen at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: arsen at gcc dot gnu.org @ 2024-07-16 19:18 UTC (permalink / raw)
  To: gcc-bugs

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

Arsen Arsenović <arsen at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
                 CC|                            |arsen at gcc dot gnu.org
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2024-07-16

--- Comment #2 from Arsen Arsenović <arsen at gcc dot gnu.org> ---
this corresponds to the four switches emitted for the coroutine implementation
after morphing these fns into coroutine functions.  the other cases are
unreachable except by corruption of the frame, perhaps we should emit calls to
either __builtin_unreachable or (IMO, better) some diagnostic hook (perhaps the
best of both worlds by emitting a call to a UBsan hook or somesuch).

anyway, the diagnostic is unactionable by the user and hence bad anyway

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

* [Bug c++/109867] -Wswitch-default reports missing default in coroutine
  2023-05-15 21:44 [Bug c++/109867] New: -Wswicht-default reports missing default in coroutine lukaslang.bugtracker at outlook dot com
  2024-01-30 14:04 ` [Bug c++/109867] -Wswitch-default " piotrwn1 at gmail dot com
  2024-07-16 19:18 ` arsen at gcc dot gnu.org
@ 2024-07-22 15:07 ` arsen at gcc dot gnu.org
  2024-08-27 21:13 ` cvs-commit at gcc dot gnu.org
  2024-08-29 12:04 ` arsen at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: arsen at gcc dot gnu.org @ 2024-07-22 15:07 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Arsen Arsenović <arsen at gcc dot gnu.org> ---
(In reply to Arsen Arsenović from comment #2)
> this corresponds to the four switches emitted for the coroutine
> implementation after morphing these fns into coroutine functions.  the other
> cases are unreachable except by corruption of the frame, perhaps we should
> emit calls to either __builtin_unreachable or (IMO, better) some diagnostic
> hook (perhaps the best of both worlds by emitting a call to a UBsan hook or
> somesuch).
> 
> anyway, the diagnostic is unactionable by the user and hence bad anyway

ah, never mind, we emit traps in the default case (which is fine), meaning we
have a default.  the reason the warning happens is that we don't use
finish_case_label, so the analysis later fails to find the default label since
we never registered it properly

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

* [Bug c++/109867] -Wswitch-default reports missing default in coroutine
  2023-05-15 21:44 [Bug c++/109867] New: -Wswicht-default reports missing default in coroutine lukaslang.bugtracker at outlook dot com
                   ` (2 preceding siblings ...)
  2024-07-22 15:07 ` arsen at gcc dot gnu.org
@ 2024-08-27 21:13 ` cvs-commit at gcc dot gnu.org
  2024-08-29 12:04 ` arsen at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-08-27 21:13 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Arsen Arsenovic <arsen@gcc.gnu.org>:

https://gcc.gnu.org/g:ff0cba200af72f2514ebc987a99027f314d4cc99

commit r15-3234-gff0cba200af72f2514ebc987a99027f314d4cc99
Author: Arsen ArsenoviÄ <arsen@aarsen.me>
Date:   Wed Jul 24 20:43:01 2024 +0200

    c++/coroutines: fix actor cases not being added to the current switch
[PR109867]

    Previously, we were building and inserting case_labels manually, which
    led to them not being added into the currently running switch via
    c_add_case_label.  This led to false diagnostics that the user could not
    act on.

            PR c++/109867

    gcc/cp/ChangeLog:

            * coroutines.cc (expand_one_await_expression): Replace uses of
            build_case_label with finish_case_label.
            (build_actor_fn): Ditto.
            (create_anon_label_with_ctx): Remove now-unused function.

    gcc/testsuite/ChangeLog:

            * g++.dg/coroutines/torture/pr109867.C: New test.

    Reviewed-by: Iain Sandoe <iain@sandoe.co.uk>

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

* [Bug c++/109867] -Wswitch-default reports missing default in coroutine
  2023-05-15 21:44 [Bug c++/109867] New: -Wswicht-default reports missing default in coroutine lukaslang.bugtracker at outlook dot com
                   ` (3 preceding siblings ...)
  2024-08-27 21:13 ` cvs-commit at gcc dot gnu.org
@ 2024-08-29 12:04 ` arsen at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: arsen at gcc dot gnu.org @ 2024-08-29 12:04 UTC (permalink / raw)
  To: gcc-bugs

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

Arsen Arsenović <arsen at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |arsen at gcc dot gnu.org
             Status|NEW                         |WAITING

--- Comment #5 from Arsen Arsenović <arsen at gcc dot gnu.org> ---
fixed on trunk, possible backport candidate

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

end of thread, other threads:[~2024-08-29 12:04 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-15 21:44 [Bug c++/109867] New: -Wswicht-default reports missing default in coroutine lukaslang.bugtracker at outlook dot com
2024-01-30 14:04 ` [Bug c++/109867] -Wswitch-default " piotrwn1 at gmail dot com
2024-07-16 19:18 ` arsen at gcc dot gnu.org
2024-07-22 15:07 ` arsen at gcc dot gnu.org
2024-08-27 21:13 ` cvs-commit at gcc dot gnu.org
2024-08-29 12:04 ` arsen 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).