public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/96251] New: co_yield incorrectly rejected in non-explicitly-constexpr generic lambda
@ 2020-07-20 14:40 yuri.kilochek at gmail dot com
  2020-07-20 14:41 ` [Bug c++/96251] " yuri.kilochek at gmail dot com
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: yuri.kilochek at gmail dot com @ 2020-07-20 14:40 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 96251
           Summary: co_yield incorrectly rejected in
                    non-explicitly-constexpr generic lambda
           Product: gcc
           Version: 10.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: yuri.kilochek at gmail dot com
  Target Milestone: ---

Created attachment 48898
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48898&action=edit
preprocessed test source

Given `test.cpp`:

    #include <coroutine>

    struct coroutine {
        struct promise_type {
            auto get_return_object() { return coroutine(); }
            auto initial_suspend() { return std::suspend_always(); }
            auto yield_value(int) { return std::suspend_always(); }
            void return_void() {}
            auto final_suspend() { return std::suspend_always(); }
            void unhandled_exception() {}
        };
    };

    int main() {
        auto f = [](auto max) -> coroutine {
            for (int i = 0; i < max; ++i) {
                co_yield i;
            }
        };

        f(10);
    }

Compiled with:

    g++ -v -save-temps -std=c++20 -fcoroutines test.cpp

The following diagnostic is produced:

    Using built-in specs.
    COLLECT_GCC=g++
    COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/10.1.0/lto-wrapper
    Target: x86_64-pc-linux-gnu
    Configured with: /build/gcc/src/gcc/configure --prefix=/usr
--libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man
--infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/
--enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++,d --with-isl
--with-linker-hash-style=gnu --with-system-zlib --enable-__cxa_atexit
--enable-cet=auto --enable-checking=release --enable-clocale=gnu
--enable-default-pie --enable-default-ssp --enable-gnu-indirect-function
--enable-gnu-unique-object --enable-install-libiberty --enable-linker-build-id
--enable-lto --enable-multilib --enable-plugin --enable-shared
--enable-threads=posix --disable-libssp --disable-libstdcxx-pch
--disable-libunwind-exceptions --disable-werror
gdc_include_dir=/usr/include/dlang/gdc
    Thread model: posix
    Supported LTO compression algorithms: zlib zstd
    gcc version 10.1.0 (GCC) 
    COLLECT_GCC_OPTIONS='-v' '-save-temps' '-std=c++2a' '-fcoroutines'
'-shared-libgcc' '-mtune=generic' '-march=x86-64'
     /usr/lib/gcc/x86_64-pc-linux-gnu/10.1.0/cc1plus -E -quiet -v -D_GNU_SOURCE
test.cpp -mtune=generic -march=x86-64 -std=c++2a -fcoroutines -fpch-preprocess
-o test.ii
    ignoring nonexistent directory
"/usr/lib/gcc/x86_64-pc-linux-gnu/10.1.0/../../../../x86_64-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
     /usr/lib/gcc/x86_64-pc-linux-gnu/10.1.0/../../../../include/c++/10.1.0
    
/usr/lib/gcc/x86_64-pc-linux-gnu/10.1.0/../../../../include/c++/10.1.0/x86_64-pc-linux-gnu
    
/usr/lib/gcc/x86_64-pc-linux-gnu/10.1.0/../../../../include/c++/10.1.0/backward
     /usr/lib/gcc/x86_64-pc-linux-gnu/10.1.0/include
     /usr/local/include
     /usr/lib/gcc/x86_64-pc-linux-gnu/10.1.0/include-fixed
     /usr/include
    End of search list.
    COLLECT_GCC_OPTIONS='-v' '-save-temps' '-std=c++2a' '-fcoroutines'
'-shared-libgcc' '-mtune=generic' '-march=x86-64'
     /usr/lib/gcc/x86_64-pc-linux-gnu/10.1.0/cc1plus -fpreprocessed test.ii
-quiet -dumpbase test.cpp -mtune=generic -march=x86-64 -auxbase test -std=c++2a
-version -fcoroutines -o test.s
    GNU C++17 (GCC) version 10.1.0 (x86_64-pc-linux-gnu)
        compiled by GNU C version 10.1.0, GMP version 6.2.0, MPFR version
4.0.2, MPC version 1.1.0, isl version isl-0.21-GMP

    GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
    GNU C++17 (GCC) version 10.1.0 (x86_64-pc-linux-gnu)
        compiled by GNU C version 10.1.0, GMP version 6.2.0, MPFR version
4.0.2, MPC version 1.1.0, isl version isl-0.21-GMP

    GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
    Compiler executable checksum: 262bfe0a9d27898ea74cb944d94238f6
    test.cpp: In instantiation of ‘main()::<lambda(auto:1)> [with auto:1 =
int]’:
    test.cpp:21:10:   required from here
    test.cpp:17:13: error: ‘co_yield’ cannot be used in a ‘constexpr’ function
       17 |             co_yield i;
          |             ^~~~~~~~

Since coroutines cannot be `constexpr` (per [dcl.constexpr]/3.3), presence of
`co_yield` should simply disqualify the lambda from being implicitly constexpr
(as it would otherwise be due to [expr.prim.lambda.closure]/4).

Interestingly, if we make the lambda non-generic (e.g. replace `auto max` with
`int max`) it compiles and works fine.

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

end of thread, other threads:[~2021-08-28 22:08 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-20 14:40 [Bug c++/96251] New: co_yield incorrectly rejected in non-explicitly-constexpr generic lambda yuri.kilochek at gmail dot com
2020-07-20 14:41 ` [Bug c++/96251] " yuri.kilochek at gmail dot com
2020-07-20 14:43 ` yuri.kilochek at gmail dot com
2020-07-21 18:53 ` iains at gcc dot gnu.org
2021-02-16  8:35 ` iains at gcc dot gnu.org
2021-02-16 20:45 ` [Bug c++/96251] [constexpr, coroutines] " iains at gcc dot gnu.org
2021-02-16 20:58 ` iains at gcc dot gnu.org
2021-02-22 21:04 ` iains at gcc dot gnu.org
2021-02-24 11:57 ` cvs-commit at gcc dot gnu.org
2021-02-24 11:58 ` iains at gcc dot gnu.org
2021-03-21 23:52 ` cvs-commit at gcc dot gnu.org
2021-03-22  0:02 ` iains at gcc dot gnu.org
2021-08-28 22:08 ` pinskia 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).