mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-01 19:58:15 +00:00
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)
This commit is contained in:
committed by
Wouter van Oortmerssen
parent
e7e4dc755d
commit
f5387387de
@@ -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)
|
||||
|
||||
@@ -26,6 +26,11 @@
|
||||
#include <intrin.h>
|
||||
#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<uint8_t>(fixed_type / 3 + 2); // 3 types each, starting from length 2.
|
||||
return static_cast<Type>(fixed_type % 3 + TYPE_INT);
|
||||
}
|
||||
|
||||
@@ -602,7 +607,7 @@ class Reference {
|
||||
|
||||
template<typename T> bool Mutate(const uint8_t *dest, T t, size_t byte_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) {
|
||||
t = flatbuffers::EndianScalar(t);
|
||||
memcpy(const_cast<uint8_t *>(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<uint8_t>(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<size_t>(1U << bit_width) == byte_width)
|
||||
if (static_cast<size_t>(static_cast<size_t>(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_
|
||||
|
||||
@@ -18,6 +18,11 @@
|
||||
#include <assert.h>
|
||||
#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<std::string> &dc, std::string *code_ptr,
|
||||
}
|
||||
|
||||
} // namespace flatbuffers
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user