Repository: pytorch
Issue: Operator registration doesn't work with noexcept functions on some compilers (c10::guts::is_function_type rejects noexcept)
Labels: module: internals,triaged

@fmassa reported that this registration:

```
namespace vision {
int64_t cuda_version() noexcept {
#ifdef WITH_CUDA
  return CUDA_VERSION;
#else
  return -1;
#endif
}
} // namespace vision

// ...

  m.def("_cuda_version", &vision::cuda_version);
```

failed with:

```
stderr: In file included from pytorch/vision/torchvision/csrc/vision.cpp:2:
In file included from caffe2/torch/script.h:3:
In file included from caffe2/torch/csrc/api/include/torch/types.h:7:
In file included from buck-out/dev/gen/caffe2/generate-code=autograd/generated/variable_factories.h/autograd/generated/variable_factories.h:12:
In file included from caffe2/torch/csrc/jit/frontend/tracer.h:9:
In file included from caffe2/torch/csrc/jit/api/object.h:5:
In file included from caffe2/torch/csrc/jit/api/method.h:5:
In file included from caffe2/torch/csrc/jit/api/function_impl.h:4:
In file included from caffe2/torch/csrc/jit/ir/ir.h:7:
In file included from caffe2/torch/csrc/jit/runtime/operator.h:13:
caffe2/torch/library.h:457:17: error: no matching constructor for initialization of 'torch::CppFunction'
    CppFunction f(std::forward<Func>(raw_f));
                ^ ~~~~~~~~~~~~~~~~~~~~~~~~~
pytorch/vision/torchvision/csrc/vision.cpp:60:5: note: in instantiation of function template specialization 'torch::Library::def<char const (&)[14], long (*)() noexcept>' requested here
  m.def("_cuda_version", &vision::cuda_version);
    ^
caffe2/torch/library.h:84:18: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'long (*)() noexcept' to 'const torch::CppFunction' for 1st argument
class CAFFE2_API CppFunction final {
                 ^
caffe2/torch/library.h:84:18: note: candidate constructor (the implicit move constructor) not viable: no known conversion from 'long (*)() noexcept' to 'torch::CppFunction' for 1st argument
class CAFFE2_API CppFunction final {
                 ^
caffe2/torch/library.h:91:12: note: candidate template ignored: requirement 'c10::guts::is_function_type<long () noexcept>::value' was not satisfied [with Func = long () noexcept]
  explicit CppFunction(Func* f, std::enable_if_t<c10::guts::is_function_type<Func>::value, std::nullptr_t> = nullptr)
           ^
caffe2/torch/library.h:101:12: note: candidate template ignored: requirement 'c10::is_compile_time_function_pointer<long (*)() noexcept>::value' was not satisfied [with FuncPtr = long (*)() noexcept]
  explicit CppFunction(FuncPtr f, std::enable_if_t<c10::is_compile_time_function_pointer<FuncPtr>::value, std::nullptr_t> = nullptr)
           ^
caffe2/torch/library.h:111:12: note: candidate template ignored: requirement 'c10::guts::is_functor<std::decay_t<long (*)() noexcept> >::value' was not satisfied [with Lambda = long (*)() noexcept]
  explicit CppFunction(Lambda&& f, std::enable_if_t<c10::guts::is_functor<std::decay_t<Lambda>>::value, std::nullptr_t> = nullptr)
           ^
caffe2/torch/library.h:194:3: note: candidate constructor not viable: requires 3 arguments, but 1 was provided
  CppFunction(c10::KernelFunction func, c10::optional<c10::impl::CppSignature> cpp_signature, std::unique_ptr<c10::FunctionSchema> schema);
  ^
1 error generated.
    When running <c++ preprocess_and_compile>.
    When building rule //pytorch/vision:_C#compile-pic-vision.cpp.odfebb6b1,platform007-clang,py3.7-platform007,shared,v8fcb3a7.
```

This problem doesn't occur on all compilers (notably, OSS had no problems) so it might be a platform007 clang specific thing.

cc @ezyang @bhosmer @smessmer @ljk53 @bdhirsh @ailzhang