From e6fa7b11333a8da26ea800bb9b7b4bbb25b10879 Mon Sep 17 00:00:00 2001 From: chronoxor Date: Wed, 12 Apr 2017 23:13:10 +0300 Subject: [PATCH] =?UTF-8?q?Fix=20Visual=20Studio=202017=20new=20warning=20?= =?UTF-8?q?(C4244:=20'argument':=20conversion=20fro=E2=80=A6=20(#4261)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix Visual Studio 2017 new warning (C4244: 'argument': conversion from 'int' to 'const char', possible loss of data) * Fix Visual Studio 2017 pedantic warnings * Fix Visual Studio 2017 pedantic warnings --- include/flatbuffers/util.h | 5 +++++ src/idl_gen_cpp.cpp | 4 ++-- tests/test.cpp | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/include/flatbuffers/util.h b/include/flatbuffers/util.h index 2bd0ae086..008b18683 100644 --- a/include/flatbuffers/util.h +++ b/include/flatbuffers/util.h @@ -114,6 +114,11 @@ inline uint64_t StringToUInt(const char *str, char **endptr = nullptr, #endif } +// Pedantic warning free version of toupper(). +inline char ToUpper(char c) { + return static_cast(::toupper(c)); +} + typedef bool (*LoadFileFunction)(const char *filename, bool binary, std::string *dest); typedef bool (*FileExistsFunction)(const char *filename); diff --git a/src/idl_gen_cpp.cpp b/src/idl_gen_cpp.cpp index 521ca8fba..95c5d71ab 100644 --- a/src/idl_gen_cpp.cpp +++ b/src/idl_gen_cpp.cpp @@ -54,7 +54,7 @@ class CppGenerator : public BaseGenerator { guard += *it + "_"; } guard += "H_"; - std::transform(guard.begin(), guard.end(), guard.begin(), ::toupper); + std::transform(guard.begin(), guard.end(), guard.begin(), ToUpper); return guard; } @@ -852,7 +852,7 @@ class CppGenerator : public BaseGenerator { std::string GenFieldOffsetName(const FieldDef &field) { std::string uname = field.name; - std::transform(uname.begin(), uname.end(), uname.begin(), ::toupper); + std::transform(uname.begin(), uname.end(), uname.begin(), ToUpper); return "VT_" + uname; } diff --git a/tests/test.cpp b/tests/test.cpp index 8011a11a8..262562a60 100644 --- a/tests/test.cpp +++ b/tests/test.cpp @@ -261,7 +261,7 @@ void AccessFlatBufferTest(const uint8_t *flatbuf, size_t length, // Test accessing a vector of sorted structs auto vecofstructs = monster->testarrayofsortedstruct(); if (vecofstructs) { // not filled in monster_test.bfbs - for (size_t i = 0; i < vecofstructs->size()-1; i++) { + for (flatbuffers::uoffset_t i = 0; i < vecofstructs->size()-1; i++) { auto left = vecofstructs->Get(i); auto right = vecofstructs->Get(i+1); TEST_EQ(true, (left->KeyCompareLessThan(right)));