Error at compile / win10 / _C10_ALWAYS_INLINE / __has_attribute(always_inline)

Hello there,

I switched recently a project from libtorch 1.7.0 to 1.8.0, under MS Visual Studio C++ 2017. We are using warning as error in our code, so I had to disable an additional warning 4624 (about automatically deleted destructor or something like that), but also had to patch a c10 macros header file to be able to compile.

The file is :…/libtorch_cuda11_release/include/c10/macros/Macros.h

When declaring _C10_ALWAYS_INLINE , the header uses __has_attribute preprocessor, which does not exist under MSVC.

The code :

#if __has_attribute(always_inline) || defined(__GNUC__)
	#define C10_ALWAYS_INLINE __attribute__((__always_inline__)) inline
#elif defined(_MSC_VER)
	#define C10_ALWAYS_INLINE __forceinline
#else
	#define C10_ALWAYS_INLINE inline
#endif	

Should be replaced by something like :

#if defined __has_attribute
#if __has_attribute(always_inline) || defined(GNUC)
#define C10_ALWAYS_INLINE attribute((always_inline)) inline
#elif defined(_MSC_VER)
#define C10_ALWAYS_INLINE __forceinline
#else
#define C10_ALWAYS_INLINE inline
#endif
#elif defined(_MSC_VER)
#define C10_ALWAYS_INLINE __forceinline
#else
#define C10_ALWAYS_INLINE inline
#endif

Or anything simpler, testing first for MSVC maybe

Could it be integrated in the nightly ? That would avoid manually patching future versions.

Best

I’m not sure, how well VS2017 is supported, as the build instructions mention:

Visual Studio 2019 version 16.7.6 (MSVC toolchain version 14.27) or higher is recommended.

CC @peterjc123

This is unrelated to VS versions and need a fix. I’ll do that.

1 Like

Fixed by [PyTorch] Fix broken build caused by keyword missing on Windows by larryliu0820 · Pull Request #53562 · pytorch/pytorch · GitHub.

2 Likes