cpp-redis / cpp_redis

C++11 Lightweight Redis client: async, thread-safe, no dependency, pipelining, multi-platform
MIT License
721 stars 199 forks source link

cpp_redis does not compile with MSVC in conformance mode or with C++20 #122

Open chriss5 opened 1 year ago

chriss5 commented 1 year ago

When building cpp_redis with Microsoft Visual Studio and switching the permissive mode off (=conformance mode on) or switching the language standard to C++20 (what implicitly enabled the conformacne mode), cpp_redis no longer compiles due to an error in optional.hpp when explanding __CPP_REDIS_LOG(1, "value_or(U&& v)\n") to cpp_redis::1(...) Error C2589 'constant': illegal token on right side of '::'

The reason is that MSVC by default sets the __cplusplus makro to 199711L even for newer language standards.

The solution is to either set an additional compiler option in the visual studio project: /Zc:__cplusplus or to update the line

if __cplusplus >= 201703L in optional.hpp to also check for _MSVC_LANG

chriss5 commented 1 year ago

I had forgotten to add the referene for MSVC's behavior and the compiler option: https://learn.microsoft.com/en-us/cpp/build/reference/zc-cplusplus?view=msvc-170