Skip to content

Incorrect noexcept specification for invoke() #32

@Raclamusi

Description

@Raclamusi

When the first argument is a noexcept member function pointer, yk::polyfill::invoke() is unconditionally decorated with noexcept(true).
In other words, is_nothrow_invocable<T (C::*)(Params...) noexcept, U, Args...>::value is always true, regardless of whether the conversions from Args... to Params... might throw an exception.

#include <yk/polyfill/functional.hpp>

struct ThrowingConvertible {
  ThrowingConvertible(int x) noexcept(false) { throw x; }
};

struct S {
  void nothrow_member_function(ThrowingConvertible) noexcept {}
};

int main() {
  try {
    // Expected: Catch the exception thrown by ThrowingConvertible
    // Actual: std::terminate() is called because invoke() is noexcept
    yk::polyfill::invoke(&S::nothrow_member_function, S{}, 42);
  }
  catch (...) {
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions