From 2d9879c1eb52961698d196576416be8692a2c9f7 Mon Sep 17 00:00:00 2001 From: Sebastian Messmer Date: Mon, 11 Feb 2019 12:29:47 -0800 Subject: [PATCH] Fix constexpr in KernelRegistrationBuilder (#16906) Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/16906 In C++11, constexpr implies const, so these methods actually wouldn't be rvalue overloads as intended but const rvalue overloads. Let's only apply the constexpr flag in C++14 to be safe. Reviewed By: bddppq Differential Revision: D13998486 fbshipit-source-id: a04d17ef0cc8f45e3d0a1ca9843d194f4f0f6f7f --- aten/src/ATen/core/dispatch/KernelRegistration.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/aten/src/ATen/core/dispatch/KernelRegistration.h b/aten/src/ATen/core/dispatch/KernelRegistration.h index eaab0c15e0267..4fef909bc04f3 100644 --- a/aten/src/ATen/core/dispatch/KernelRegistration.h +++ b/aten/src/ATen/core/dispatch/KernelRegistration.h @@ -228,7 +228,7 @@ class KernelRegistrationBuilder final { * @param dispatch_key dispatch key to register the function to * @return "this" for method chaining */ - constexpr KernelRegistrationBuilder dispatchKey(TensorTypeId dispatch_key) && { + AT_CPP14_CONSTEXPR KernelRegistrationBuilder dispatchKey(TensorTypeId dispatch_key) && { static_assert(!(FieldsPresentFlags & DISPATCH_KEY_PRESENT), "Tried to define kernel twice in same op registration"); return KernelRegistrationBuilder(std::move(op_), std::move(dispatch_key), kernel_, cache_creator_); } @@ -239,7 +239,7 @@ class KernelRegistrationBuilder final { * @return "this" for method chaining */ template - constexpr KernelRegistrationBuilder kernel() && { + AT_CPP14_CONSTEXPR KernelRegistrationBuilder kernel() && { static_assert(!(FieldsPresentFlags & KERNEL_PRESENT), "Tried to define kernel twice in same op registration"); // TODO Better error message when kernel function mismatches, one common mismatch is missing cache parameter or cache parameter present while not expected. return KernelRegistrationBuilder(std::move(op_), std::move(dispatch_key_), kernel_func, cache_creator_); @@ -251,7 +251,7 @@ class KernelRegistrationBuilder final { * @return "this" for method chaining */ template - constexpr KernelRegistrationBuilder kernel() && { + AT_CPP14_CONSTEXPR KernelRegistrationBuilder kernel() && { // TODO Better error message if FuncType is not a func type return std::move(*this).template kernel<&detail::wrap_kernel::call>(); } @@ -262,7 +262,7 @@ class KernelRegistrationBuilder final { * @return "this" for method chaining */ template - constexpr KernelRegistrationBuilder withCache() && { + AT_CPP14_CONSTEXPR KernelRegistrationBuilder withCache() && { static_assert(!(FieldsPresentFlags & CACHE_PRESENT), "Tried to define cache twice in same op registration"); static_assert(std::is_base_of::value, "Cache must inherit from c10::KernelCache");