Commit f5387387 authored by chronoxor's avatar chronoxor Committed by Wouter van Oortmerssen

Pedantic Visual Studio build (/W4 /WX) (#4214)

* Pedantic Visual Studio build (/W4 /WX)

* Pedantic Visual Studio build (/W4 /WX)

* Pedantic Visual Studio build (/W4 /WX)

* Remove /wd4512 from CMakeLists.txt

* Suppress Visual Studio 4512 warning ('class' : assignment operator could not be generated)
parent e7e4dc75
...@@ -144,8 +144,8 @@ elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") ...@@ -144,8 +144,8 @@ elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
"${CMAKE_CXX_FLAGS} -fsigned-char") "${CMAKE_CXX_FLAGS} -fsigned-char")
elseif(MSVC) elseif(MSVC)
# warning C4512: assignment operator could not be generated # Visual Studio pedantic build settings
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4512") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /WX")
endif() endif()
if(FLATBUFFERS_CODE_COVERAGE) if(FLATBUFFERS_CODE_COVERAGE)
......
...@@ -26,6 +26,11 @@ ...@@ -26,6 +26,11 @@
#include <intrin.h> #include <intrin.h>
#endif #endif
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable: 4127) // C4127: conditional expression is constant
#endif
namespace flexbuffers { namespace flexbuffers {
class Reference; class Reference;
...@@ -105,7 +110,7 @@ inline Type ToTypedVectorElementType(Type t) { ...@@ -105,7 +110,7 @@ inline Type ToTypedVectorElementType(Type t) {
inline Type ToFixedTypedVectorElementType(Type t, uint8_t *len) { inline Type ToFixedTypedVectorElementType(Type t, uint8_t *len) {
assert(IsFixedTypedVector(t)); assert(IsFixedTypedVector(t));
auto fixed_type = t - TYPE_VECTOR_INT2; auto fixed_type = t - TYPE_VECTOR_INT2;
*len = fixed_type / 3 + 2; // 3 types each, starting from length 2. *len = static_cast<uint8_t>(fixed_type / 3 + 2); // 3 types each, starting from length 2.
return static_cast<Type>(fixed_type % 3 + TYPE_INT); return static_cast<Type>(fixed_type % 3 + TYPE_INT);
} }
...@@ -602,7 +607,7 @@ class Reference { ...@@ -602,7 +607,7 @@ class Reference {
template<typename T> bool Mutate(const uint8_t *dest, T t, size_t byte_width, template<typename T> bool Mutate(const uint8_t *dest, T t, size_t byte_width,
BitWidth value_width) { BitWidth value_width) {
auto fits = static_cast<size_t>(1U << value_width) <= byte_width; auto fits = static_cast<size_t>(static_cast<size_t>(1U) << value_width) <= byte_width;
if (fits) { if (fits) {
t = flatbuffers::EndianScalar(t); t = flatbuffers::EndianScalar(t);
memcpy(const_cast<uint8_t *>(dest), &t, byte_width); memcpy(const_cast<uint8_t *>(dest), &t, byte_width);
...@@ -1073,7 +1078,7 @@ class Builder FLATBUFFERS_FINAL_CLASS { ...@@ -1073,7 +1078,7 @@ class Builder FLATBUFFERS_FINAL_CLASS {
auto byte_width = 1U << alignment; auto byte_width = 1U << alignment;
buf_.insert(buf_.end(), flatbuffers::PaddingBytes(buf_.size(), byte_width), buf_.insert(buf_.end(), flatbuffers::PaddingBytes(buf_.size(), byte_width),
0); 0);
return byte_width; return static_cast<uint8_t>(byte_width);
} }
void WriteBytes(const void *val, size_t size) { void WriteBytes(const void *val, size_t size) {
...@@ -1177,7 +1182,7 @@ class Builder FLATBUFFERS_FINAL_CLASS { ...@@ -1177,7 +1182,7 @@ class Builder FLATBUFFERS_FINAL_CLASS {
auto offset = offset_loc - u_; auto offset = offset_loc - u_;
// Does it fit? // Does it fit?
auto bit_width = WidthU(offset); auto bit_width = WidthU(offset);
if (static_cast<size_t>(1U << bit_width) == byte_width) if (static_cast<size_t>(static_cast<size_t>(1U) << bit_width) == byte_width)
return bit_width; return bit_width;
} }
assert(false); // Must match one of the sizes above. assert(false); // Must match one of the sizes above.
...@@ -1340,4 +1345,8 @@ class Builder FLATBUFFERS_FINAL_CLASS { ...@@ -1340,4 +1345,8 @@ class Builder FLATBUFFERS_FINAL_CLASS {
} // namespace flexbuffers } // namespace flexbuffers
#if defined(_MSC_VER)
#pragma warning(pop)
#endif
#endif // FLATBUFFERS_FLEXBUFFERS_H_ #endif // FLATBUFFERS_FLEXBUFFERS_H_
...@@ -18,6 +18,11 @@ ...@@ -18,6 +18,11 @@
#include <assert.h> #include <assert.h>
#include "flatbuffers/util.h" #include "flatbuffers/util.h"
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable: 4127) // C4127: conditional expression is constant
#endif
namespace flatbuffers { namespace flatbuffers {
void CodeWriter::operator+=(std::string text) { void CodeWriter::operator+=(std::string text) {
...@@ -156,3 +161,8 @@ void GenComment(const std::vector<std::string> &dc, std::string *code_ptr, ...@@ -156,3 +161,8 @@ void GenComment(const std::vector<std::string> &dc, std::string *code_ptr,
} }
} // namespace flatbuffers } // namespace flatbuffers
#if defined(_MSC_VER)
#pragma warning(pop)
#endif
...@@ -24,6 +24,11 @@ ...@@ -24,6 +24,11 @@
#include "src/compiler/cpp_generator.h" #include "src/compiler/cpp_generator.h"
#include "src/compiler/go_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 { namespace flatbuffers {
class FlatBufMethod : public grpc_generator::Method { class FlatBufMethod : public grpc_generator::Method {
...@@ -269,3 +274,7 @@ bool GenerateCppGRPC(const Parser &parser, ...@@ -269,3 +274,7 @@ bool GenerateCppGRPC(const Parser &parser,
} // namespace flatbuffers } // namespace flatbuffers
#if defined(_MSC_VER)
#pragma warning(pop)
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment