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

stream009 <stream009 at gmail dot com> changed:

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

--- Comment #42 from stream009 <stream009 at gmail dot com> ---
I got strange compile error when I use coroutine with UBSAN.

The weird thing is error is reported in compile time not runtime.
The code compile fine without UBSAN.

GCC version: 11.1
compile option: -std=c++20 -Wall -Wextra -pedantic-errors -fcoroutines
-fsanitize=undefined
compiler explorer link: https://godbolt.org/z/Yva6b1YTz

It seems error happen only coroutine that doesn't return value (promise has
return_void() defined). I don't get error with coroutine that return value.
(https://godbolt.org/z/3jcvYPcqa)

Let me know if I should report this as separate bug.

=== begin source ===
#include <coroutine>

struct result
{
    struct promise_type
    {
        std::suspend_never initial_suspend() { return {}; }
        std::suspend_never final_suspend() noexcept { return {}; }

        result get_return_object() { return {}; }

        void return_void() {}

        void unhandled_exception() {}
    };
};

result error(int i)
{
    if (i == 0) {
        co_return;
    }
}
=== end source ===

=== begin compile error ===
<source>: In function 'void _Z5errori.actor(error(int)::_Z5errori.frame*)':
<source>:21:9: warning: '<anonymous>' may be used uninitialized
[-Wmaybe-uninitialized]
   21 |         co_return;
      |         ^~~~~~~~~
<source>:21:9: note: '<anonymous>' was declared here
   21 |         co_return;
      |         ^~~~~~~~~
=== end compile error ===

Reply via email to