Why is gcc-10 not seeing keywords related to coroutine ts?
Asked Answered
A

1

7

I have installed gcc-10 compiler on my ubuntu 20.04. I needed to test the work of coroutine ts, so I found an example using coroutines and tried to compile it.

exemple:

#include <coroutine>
#include <iostream>

struct simple {
    static inline int x = 0;
    int id = 0;
    simple() : id{ x++ } { std::cout << id << " constructed\n"; }
    simple(simple&&) : id{ x++ } { std::cout << id << " move constructed\n"; }
    ~simple() { std::cout << id << " destructed\n"; }

    struct promise_type {
        simple get_return_object() { return {}; }
        void return_void() {}
        void unhandled_exception() { std::terminate(); }
        auto initial_suspend() noexcept { return std::suspend_never{}; }
        auto final_suspend() noexcept { return std::suspend_never{}; }
    };
};

simple f() { co_return; }

int main() {
    f();
}

Even though I made gcc-10 the default compiler in clion, added the required flag and included the standard 20 in cmake, the compiler still throws an error. Error on the co_return keyword

Std::experimental::coroutine_traits type was not found; include <experimental/coroutine> before defining a coroutine

This is strange because the heading is included without a space, and functions from it are also available.

cmake:

cmake_minimum_required(VERSION 3.17)
project(test6)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcoroutines")
add_executable(test6 main.cpp)

How can this gap be resolved?

I use g++ version 10.2.0 and

Package: libstdc++-10-dev-mips64r6-cross
Architecture: all
Version: 10.2.0-5ubuntu1~20.04cross1
Alkyd answered 27/11, 2020 at 15:45 Comment(12)
What does "the heading is included without a space" mean? The code you posted doesn't #include it. Is that code complete? If not, please make it so.Craze
<coroutine> should work, why are you using <experimental/coroutine>?Acromion
So, have you tried to include <experimental/coroutine> as the error suggests? The support in the g++/libstc++ versions you have might still be partly experimental (or just not working). What versions are those?Craze
@cigien, That's just the point, I use <coroutines>Alkyd
Ah, I see. Thanks for adding the code to the question.Acromion
The weird thing is that suspend_never found in <coroutine> works but keywords don'tAlkyd
works for me.Marcomarconi
@MarekR Huh. gcc10.1 does an additional move-construction that gcc10.2 doesn't :) Seems the optimizer got a little better.Acromion
Post what versions of g++ and libstdc++ you are using.Craze
@underscore_d, g++ version 10.2.0Alkyd
@underscore_d, Package: libstdc++-10-dev-mips64r6-cross Architecture: all Version: 10.2.0-5ubuntu1~20.04cross1Alkyd
Please add all this relevant information to the question, not as a comment.Acromion
S
0

Std::experimental::coroutine_traits type was not found; include <experimental/coroutine> before defining a coroutine

This is a clang error. GCC has never provided an <experimental/coroutine> header, nor issued this error. So this error means you're compiling with Clang, not GCC 10.

Suber answered 11/9 at 14:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.