lewissbaker / cppcoro

A library of C++ coroutine abstractions for the coroutines TS
MIT License
3.43k stars 472 forks source link

Task example file: fatal error: 'stdexcept' file not found with Clang 6.0.1 #85

Closed marcoippolito closed 6 years ago

marcoippolito commented 6 years ago

Compiling this file with clang 6.0.1 :

`#include <cppcoro/task.hpp>
namespace cppcoro
{
  template<typename T>
  class task
  {
  public:
    using promise_type = <unspecified>;
    using value_type = T;
    task() noexcept;
    task(task&& other) noexcept;
    task& operator=(task&& other);
    // task is a move-only type.
    task(const task& other) = delete;
    task& operator=(const task& other) = delete;
    // Query if the task result is ready.
    bool is_ready() const noexcept;
    // Wait for the task to complete and return the result or rethrow the
    // exception if the operation completed with an unhandled exception.  
    // If the task is not yet ready then the awaiting coroutine will be
    // suspended until the task completes. If the the task is_ready() then
    // this operation will return the result synchronously without suspending.
    <unspecified> operator co_await() const & noexcept;
    <unspecified> operator co_await() const && noexcept;
    // Returns an awaitable that can be co_await'ed to suspend the current
    // coroutine until the task completes.
   // The 'co_await t.when_ready()' expression differs from 'co_await t' in
    // that when_ready() only performs synchronisation, it does not return
    // the result or rethrow the exception.

    // This can be useful if you want to synchronise with the task without the possibility of it throwing an 
    // exception
    <unspecified> when_ready() const noexcept;
   };

  template<typename T>
  void swap(task<T>& a, task<T>& b);
  // Apply func() to the result of the task, returning a new task that yields the result of 'func(co_await 
  // task)'.
  template<typename FUNC, typename T>
  task<std::invoke_result_t<FUNC, T&&>> fmap(FUNC func, task<T> task);

   // Call func() after task completes, returning a task containing the
  // result of func().
  template<typename FUNC>
  task<std::invoke_result_t<FUNC>> fmap(FUNC func, task<void> task);
 }
 `

Compiling:

`clang++ -fcoroutines-ts -stdlib=libc++ -Qunused-arguments -std=c++17 taskExample01.cpp   
-otaskExample01
In file included from taskExample01.cpp:1:
In file included from /usr/include/cppcoro/task.hpp:9:
/usr/include/cppcoro/broken_promise.hpp:8:10: fatal error: 'stdexcept' file not found
#include <stdexcept>
         ^~~~~~~~~~~
1 error generated.
`

But when compiling such a simple file:

`#include <stdexcept>
int main() {
  return 0;
}

clang++ -std=c++17 stdexcept.cpp -ostdexcept.cpp ./stdexcept.cpp`

clang -v clang version 6.0.1

So... how to solve the problem? Marco

lewissbaker commented 6 years ago

It looks like it might be a libc++ configuration issue. The main difference I can see with the two examples you gave is the lack of -stdlib=libc++. Maybe the latter is falling back to stdlibc++ instead.

I think there are some different modes you can compile libc++ with, some of which don’t support exceptions. Try checking your libc++ installation and check that you can build the same trivial example with -stlib=libc++.