[clang] [clang] Add support for MSVC force inline attrs (PR #185282)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Wed May 27 06:59:02 PDT 2026


================
@@ -5181,6 +5181,18 @@ OptimizeNoneAttr *Sema::mergeOptimizeNoneAttr(Decl *D,
 }
 
 static void handleAlwaysInlineAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
+  AlwaysInlineAttr AIA(S.Context, AL);
+  if (!S.getLangOpts().MicrosoftExt &&
----------------
AaronBallman wrote:

> This forces me to disable this warning because of the usage `[[gnu::always_inline, msvc::forceinline]]`.

The idiomatic approach is to put the attributes behind a macro, as in:
```
#if __has_cpp_attribute(msvc::forceinline)
#define MSVC_FORCEINLINE [[msvc::forceinline]]
#else
#define MSVC_FORCEINLINE
#endif

#if __has_cpp_attribute(gnu::always_inline)
#define GNU_ALWAYS_INLINE [[gnu::always_inline]]
#else
#define GNU_ALWAYS_INLINE
#endif
```
this way the macros only expand when the attribute is actually known.

> Some other less esoteric [[msvc:: attributes are left unguarded, such as the opposite of the newly added attributes, [[msvc::noinline]]: https://godbolt.org/z/W8519n6d1

That's a compiler bug; the attribute should be diagnosed.

https://github.com/llvm/llvm-project/pull/185282


More information about the cfe-commits mailing list