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
#include
it. Is that code complete? If not, please make it so. – Craze<coroutine>
should work, why are you using<experimental/coroutine>
? – Acromioninclude <experimental/coroutine>
as the error suggests? The support in theg++
/libstc++
versions you have might still be partly experimental (or just not working). What versions are those? – Crazeg++
andlibstdc++
you are using. – Craze