From 3a3638be50c636e7b7eb4f519ed8347f2de31d36 Mon Sep 17 00:00:00 2001 From: Nikita Shulga <2453524+malfet@users.noreply.github.com> Date: Sat, 7 Dec 2024 01:05:53 +0000 Subject: [PATCH] [BE] Enable Scalar.h compilation on 32-bit system (#142235) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit By hiding ambiguous Scalar(long long) constructor behind `std::enable_if_t` Followup after https://github.com/pytorch/pytorch/pull/141244 Test Plan: Run `printf "#include \n c10::Scalar x(3);" | gcc -x c++ -std=c++17 -I. -Ibuild - -c` on ARMv7 system. Before this change it failed with: ``` In file included from :1: ./c10/core/Scalar.h:83:3: error: ‘c10::Scalar::Scalar(long long int)’ cannot be overloaded with ‘c10::Scalar::Scalar(int64_t)’ 83 | Scalar(long long vv) : Scalar(vv, true) {} | ^~~~~~ ./c10/core/Scalar.h:50:3: note: previous declaration ‘c10::Scalar::Scalar(int64_t)’ 50 | Scalar(type vv) : Scalar(vv, true) {} | ^~~~~~ ./c10/core/ScalarType.h:288:3: note: in expansion of macro ‘DEFINE_IMPLICIT_CTOR’ 288 | _(int64_t, Long) \ | ^ ./c10/core/Scalar.h:52:3: note: in expansion of macro ‘AT_FORALL_SCALAR_TYPES_AND7’ 52 | AT_FORALL_SCALAR_TYPES_AND7( | ^~~~~~~~~~~~~~~~~~~~~~~~~~~ ``` Pull Request resolved: https://github.com/pytorch/pytorch/pull/142235 Approved by: https://github.com/Skylion007 --- c10/core/Scalar.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/c10/core/Scalar.h b/c10/core/Scalar.h index 6e13f0ede60..9d1dad2d993 100644 --- a/c10/core/Scalar.h +++ b/c10/core/Scalar.h @@ -80,7 +80,9 @@ class C10_API Scalar { static_assert( sizeof(void*) != 8 || std::is_same_v, "int64_t is the same as long on 64 bit Linux"); +#if LONG_MAX != INT_MAX Scalar(long long vv) : Scalar(vv, true) {} +#endif /* not 32-bit system */ #endif Scalar(uint16_t vv) : Scalar(vv, true) {}