diff --git a/build_defs/cpp_opts.bzl b/build_defs/cpp_opts.bzl index a1d10aa23ec0..e0b031b0921f 100644 --- a/build_defs/cpp_opts.bzl +++ b/build_defs/cpp_opts.bzl @@ -14,14 +14,12 @@ COPTS = select({ "/wd4506", # no definition for inline function 'function' "/wd4800", # 'type' : forcing value to bool 'true' or 'false' (performance warning) "/wd4996", # The compiler encountered a deprecated declaration. - "/std:c++14", # Use C++14 ], "//conditions:default": [ "-DHAVE_ZLIB", "-Woverloaded-virtual", "-Wno-sign-compare", "-Werror", - "-std=c++14", # Protobuf requires C++14. ], }) # Android and MSVC builds do not need to link in a separate pthread library. diff --git a/src/google/protobuf/stubs/common.h b/src/google/protobuf/stubs/common.h index cbcee3c9262e..4d9febcbd650 100644 --- a/src/google/protobuf/stubs/common.h +++ b/src/google/protobuf/stubs/common.h @@ -47,6 +47,24 @@ #include "google/protobuf/stubs/platform_macros.h" #include "google/protobuf/stubs/port.h" +// Enforce C++14 as the minimum. +#if defined(_MSVC_LANG) +#if _MSVC_LANG < 201402L +#error "C++ versions less than C++14 are not supported." +#endif // _MSVC_LANG < 201402L +#elif defined(__cplusplus) +// Special-case GCC < 5.0, as it has a strange __cplusplus value for C++14 +#if defined(__GNUC__) && __GNUC__ < 5 +#if __cplusplus < 201300L +#error "C++ versions less than C++14 are not supported." +#endif // __cplusplus < 201300L +#else // defined(__GNUC__) && __GNUC__ < 5 +#if __cplusplus < 201402L +#error "C++ versions less than C++14 are not supported." +#endif // __cplusplus < 201402L +#endif // defined(__GNUC__) && __GNUC__ < 5 +#endif + #ifndef PROTOBUF_USE_EXCEPTIONS #if defined(_MSC_VER) && defined(_CPPUNWIND) #define PROTOBUF_USE_EXCEPTIONS 1