Search code examples
c++c++17if-constexpr

MSVC compiler warning c4984


I'm trying to implement a DLL and offer some interfaces to a legacy VS2017 C++14 project which I cannot control. (Original Post).
I want to use if constexpr expression in my header files, and found the compiler would complain about C4984. Not sure what is the meaning "portable":

If you require C++11 or C++14 compatibility, this expression isn't portable.

C4984 is issued as an error by default, but it's suppressible.

I added #pragma warning(disable : 4984) before my if constexpr expression, and found the legacy project can compile and operate well, so do I need to worry about the "portable" things?


Solution

  • if constexpr is a C++17 feature. It can't be used in C++14. If a compiler is allowing it in C++14 mode (with a warning), then this is as an extension. Other compilers, especially older ones, will not do so.

    #pragma warning(disable : 4984) is certainly not portable. It is MSVC-specific.