This fixes a surprising behavior where changing an existing function_ref
to std::function can break some code in a subtle manner. Here is the
pattern:
void foo(llvm::function_ref<void()) callback) {
  if (callback) callback();
}
void bar(llvm::function_ref<void()) callback) {
  foo(callback);
  // do something else with callback, accept an empty callback.
}Assuming bar needs to change to take a std::function (for example
to be able to store it), the code in foo() would crash if callback
is a default constructed function.
Instead of exposing this as an extra c'tor template parameter, would it make sense to split this out?
// Handles construction from an empty callable (for example a default // constructed std::function) and ensure that bool conversion to `false` is // propagated. template <typename Callable, std::enable_if_t<std::is_constructible<bool, Callable>::value> * = nullptr> static Ret get_callback(const Callable &callable) { return callable ? callback_fn<std::remove_reference_t<Callable>> : nullptr; } template <typename Callable> static Ret get_callback(...) { return callback_fn<std::remove_reference_t<Callable>>; } public: ...and then, on line 66: