Skip to content

Commit

Permalink
Fix some warnings on MSVC
Browse files Browse the repository at this point in the history
  • Loading branch information
tuokri committed Jun 24, 2024
1 parent 6f8870a commit dd14a5f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 9 deletions.
4 changes: 2 additions & 2 deletions include/umb/coding.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,12 +322,12 @@ decode_string(
char_buf.reserve(str_size);

char16_t previous = 0x00;
auto shift = 0;
byte shift = 0;
for (const auto& byte: byte_buf)
{
if (shift == 8)
{
char_buf.emplace_back(previous | (byte << shift));
char_buf.emplace_back(static_cast<char16_t>(previous | (byte << shift)));
}
else
{
Expand Down
18 changes: 18 additions & 0 deletions include/umb/umb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,24 @@

#pragma once

#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
#define UMB_WINDOWS 1
#else
#define UMB_WINDOWS 0
#endif

#ifdef _MSC_VER
#define UMB_SUPPRESS_MSVC_WARNING(n) __pragma(warning(suppress : n))
#define UMB_WARNING_PUSH_MSVC __pragma(warning(push))
#define UMB_WARNING_POP_MSVC __pragma(warning(pop))
#define UMB_WARNING_DISABLE_MSVC(n) __pragma(warning(disable: n))
#else
#define UMB_SUPPRESS_MSVC_WARNING(n)
#define UMB_WARNING_PUSH_MSVC
#define UMB_WARNING_POP_MSVC
#define UMB_WARNING_DISABLE_MSVC(n)
#endif

#include "umb/coding.hpp"
#include "umb/constants.hpp"
#include "umb/floatcmp.hpp"
Expand Down
14 changes: 7 additions & 7 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
#include "umb/umb.hpp"
// Always include meta explicitly, needed by the generator
// even if not doing a meta build for generated messages.
#include "umb/meta.hpp"

#if UMB_WINDOWS

// Silence "Please define _WIN32_WINNT or _WIN32_WINDOWS appropriately".
#include <SDKDDKVer.h>
Expand All @@ -39,11 +44,6 @@
#include <boost/process/v2.hpp>
#include <boost/program_options.hpp>

#include "umb/umb.hpp"
// Always include meta explicitly, needed by the generator
// even if not doing a meta build for generated messages.
#include "umb/meta.hpp"

namespace
{

Expand Down Expand Up @@ -381,7 +381,7 @@ constexpr T var(const inja::Arguments& args)
auto action = args.at(1)->get<std::string>();

boost::algorithm::to_upper(action);
VarAction va = g_str_to_varaction.at(action);
const VarAction va = g_str_to_varaction.at(action);

T value;

Expand Down
3 changes: 3 additions & 0 deletions tests/test_coding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ TEST_CASE("encode decode long unicode string")
testmessages::umb::testmsg msg1;
testmessages::umb::testmsg msg2;

UMB_WARNING_PUSH_MSVC
UMB_WARNING_DISABLE_MSVC(4566)
constexpr auto raw_str = u"\u4b9f\uc09d\ubfe3\ubc86\ube5a"
"\uc172\uc2a3\u9b33\uc416\ufc4b"
"\u51b9\ufa94\uc81d\u8d71\u96f4"
Expand All @@ -128,6 +130,7 @@ TEST_CASE("encode decode long unicode string")
"\ua783\u11f0\u5011\uff70\u81ec"
"\u0e57\u5a5e\u3ac9\u0075\u0067"
"\u0069\u0066";
UMB_WARNING_POP_MSVC

msg1.set_ffffff(raw_str);

Expand Down

0 comments on commit dd14a5f

Please sign in to comment.