Skip to content

gstring.h/gmacros.h: Avoid compiler warnings on Visual Studio

Chun-wei Fan requested to merge fix-c4141 into main


From the commit message:

The recent optimizations to gstring.h used G_ALWAYS_INLINE (meaning __forceinline on Visual Studio) together with static inline, which will cause warning C4141 indicating that inline was used more than once on the function.

Avoid this by using a macro to just use __forceinline on Visual Studio, and use the current approach otherwise. dropping the inline keyword in the definitions

In the recent changes in gstring.h and gmacros.h, some warnings appear when building items using Visual Studio, where:

  • Warning C4141 shows up whenever gstring.h is included, as we end up using __forceinline with inline.
  • Warning C5051 shows up whenever gmacros.h is included in a pre-C++-20 code in Visual Studio 2019 16.7.x or later, as the C++ attribute [[msvc::forceinline]] and so forth are only supported since C++-20.

This attempts to rememedy things by:

  • Using #pragma directives to disable warning C4141 momentarily in gstring.h.
  • Change G_CXX_STD_CHECK_VERSION (11) to G_CXX_STD_CHECK_VERSION (20) as needed in gmacros.h

Fixes issue #2905 (closed).

With blessings, thank you!

Edited by Chun-wei Fan

Merge request reports