diff --git a/CMakeLists.txt b/CMakeLists.txt index bc716102f..affa05b79 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -144,8 +144,8 @@ elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") "${CMAKE_CXX_FLAGS} -fsigned-char") elseif(MSVC) - # warning C4512: assignment operator could not be generated - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4512") + # Visual Studio pedantic build settings + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /WX") endif() if(FLATBUFFERS_CODE_COVERAGE) diff --git a/include/flatbuffers/flexbuffers.h b/include/flatbuffers/flexbuffers.h index a5d24fd4f..3bd86f72b 100644 --- a/include/flatbuffers/flexbuffers.h +++ b/include/flatbuffers/flexbuffers.h @@ -26,6 +26,11 @@ #include #endif +#if defined(_MSC_VER) +#pragma warning(push) +#pragma warning(disable: 4127) // C4127: conditional expression is constant +#endif + namespace flexbuffers { class Reference; @@ -105,7 +110,7 @@ inline Type ToTypedVectorElementType(Type t) { inline Type ToFixedTypedVectorElementType(Type t, uint8_t *len) { assert(IsFixedTypedVector(t)); auto fixed_type = t - TYPE_VECTOR_INT2; - *len = fixed_type / 3 + 2; // 3 types each, starting from length 2. + *len = static_cast(fixed_type / 3 + 2); // 3 types each, starting from length 2. return static_cast(fixed_type % 3 + TYPE_INT); } @@ -602,7 +607,7 @@ class Reference { template bool Mutate(const uint8_t *dest, T t, size_t byte_width, BitWidth value_width) { - auto fits = static_cast(1U << value_width) <= byte_width; + auto fits = static_cast(static_cast(1U) << value_width) <= byte_width; if (fits) { t = flatbuffers::EndianScalar(t); memcpy(const_cast(dest), &t, byte_width); @@ -1073,7 +1078,7 @@ class Builder FLATBUFFERS_FINAL_CLASS { auto byte_width = 1U << alignment; buf_.insert(buf_.end(), flatbuffers::PaddingBytes(buf_.size(), byte_width), 0); - return byte_width; + return static_cast(byte_width); } void WriteBytes(const void *val, size_t size) { @@ -1177,7 +1182,7 @@ class Builder FLATBUFFERS_FINAL_CLASS { auto offset = offset_loc - u_; // Does it fit? auto bit_width = WidthU(offset); - if (static_cast(1U << bit_width) == byte_width) + if (static_cast(static_cast(1U) << bit_width) == byte_width) return bit_width; } assert(false); // Must match one of the sizes above. @@ -1340,4 +1345,8 @@ class Builder FLATBUFFERS_FINAL_CLASS { } // namespace flexbuffers +#if defined(_MSC_VER) +#pragma warning(pop) +#endif + #endif // FLATBUFFERS_FLEXBUFFERS_H_ diff --git a/src/code_generators.cpp b/src/code_generators.cpp index 871063536..929546995 100644 --- a/src/code_generators.cpp +++ b/src/code_generators.cpp @@ -18,6 +18,11 @@ #include #include "flatbuffers/util.h" +#if defined(_MSC_VER) +#pragma warning(push) +#pragma warning(disable: 4127) // C4127: conditional expression is constant +#endif + namespace flatbuffers { void CodeWriter::operator+=(std::string text) { @@ -156,3 +161,8 @@ void GenComment(const std::vector &dc, std::string *code_ptr, } } // namespace flatbuffers + +#if defined(_MSC_VER) +#pragma warning(pop) +#endif + diff --git a/src/idl_gen_grpc.cpp b/src/idl_gen_grpc.cpp index 10513eb56..2daeac9ae 100644 --- a/src/idl_gen_grpc.cpp +++ b/src/idl_gen_grpc.cpp @@ -24,6 +24,11 @@ #include "src/compiler/cpp_generator.h" #include "src/compiler/go_generator.h" +#if defined(_MSC_VER) +#pragma warning(push) +#pragma warning(disable: 4512) // C4512: 'class' : assignment operator could not be generated +#endif + namespace flatbuffers { class FlatBufMethod : public grpc_generator::Method { @@ -269,3 +274,7 @@ bool GenerateCppGRPC(const Parser &parser, } // namespace flatbuffers +#if defined(_MSC_VER) +#pragma warning(pop) +#endif +