Skip to content

<experimental/generator>: error C2980 when compiling with /kernel (regression) #1323

Description

Describe the bug
Following the changes from PR #1219, using the experimental/generator header in code built with /kernel (and hence no exception handling) now fails to compile with error C2980.

Command-line test case

C:\Users\kobyk\Documents\Stuff\ge>type ge.cpp
#include <malloc.h>
#include <coroutine>
#include <experimental/generator>

struct WDFQUEUE{};

namespace foo {

template <typename T>
class PoolAllocator final {
public:
    using value_type = T;
    using pointer = T*;
    using const_pointer = const T*;
    using reference = T&;
    using const_reference = const T&;
    using size_type = std::size_t;
    using difference_type = std::ptrdiff_t;

    template <class U>
    struct rebind {
        using other = PoolAllocator<T>;
    };

    pointer allocate(size_t size) noexcept {
        return static_cast<pointer>(malloc(size));
    }

    void deallocate(pointer ptr, [[maybe_unused]] size_t size) noexcept {

        free(ptr);
    }
};

template <typename T>
using Generator = std::experimental::generator<T, PoolAllocator<char>>;

class IteratedRequest final
{
public:
        bool valid() const { return true; }
        bool next(WDFQUEUE queue) { return true; }
};

Generator<IteratedRequest> IterateRequests(WDFQUEUE queue) {

    IteratedRequest currentRequest;
    while (currentRequest.next(queue)) {
        if (!currentRequest.valid()) {
            continue;
        }
        co_yield currentRequest;
    }
}

}
C:\Users\kobyk\Documents\Stuff\ge>cl /kernel /nologo /std:c++latest /c ge.cpp
ge.cpp
ge.cpp(54): error C2980: C++ exception handling is not supported with /kernel

Expected behavior
Previously, generators with a non-throwing allocator worked with code built with /kernel.
Furthermore, removing the unhandled_exception() function added by the PR results in the code compiling successfully.

STL version
Microsoft Visual Studio Community 2019 Preview
Version 16.8.0 Preview 3.1

Additional context
Switching back to legacy coroutines (i.e., including <experimental/coroutine> instead of <coroutine> and adding /await to the compiler command line) also resolves the C2980 error.

Casey Carter (@CaseyCarter)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixedSomething works now, yay!

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions