Skip to content

MSVC warnings#422

Open
JurgenLB wants to merge 4 commits intoThalhammer:masterfrom
JurgenLB:master
Open

MSVC warnings#422
JurgenLB wants to merge 4 commits intoThalhammer:masterfrom
JurgenLB:master

Conversation

@JurgenLB
Copy link
Contributor

@JurgenLB JurgenLB commented Mar 8, 2026

My previous Attemp seems to focused on other conversions (BN_num_bytes, HMAC, EVP_PKEY_size, EVP_VerifyFinal).
Now I revert #405 and #408 except;
jwt.h:2635
as_date() passes double to std::chrono::seconds(), narrowed to __time64_t
return date(std::chrono::seconds(static_cast<int64_t>(std::llround(as_number()))));

traits/open-source-parsers-jsoncpp/traits.h:90
as_integer() returns val.asInt64() (Int64) implicitly narrowed to integer_type (int)
return static_cast<integer_type>(val.asInt64());

My problem was the order off import, The Windows Libraries bundle version of jwt-cpp used a older version where these fixes haven't been applied yet.
But by changing the include order I found the core problem.

Kind Regards

@prince-chrismc
Copy link
Collaborator

Can you please share the compiler flags so we can verify the changes?

We typically dont make changes to picojson as its a bundled dependencies and the goal is to keep it in sync.

I believe int64 is a better type for JSON values so intger_type shoube that rather than a cast? Need to double check what all the other traits are.

@JurgenLB
Copy link
Contributor Author

JurgenLB commented Mar 8, 2026

I did use Copilot for finding a solution.
I try without changing picojson.

Submodule 'extern/jwtcpp' (https://github.com/Thalhammer/jwt-cpp) registered for path 'extern/jwtcpp'
Cloning into 'C:/projects/domoticz/extern/jwtcpp'...
Submodule path 'extern/jwtcpp': checked out 'b12ab284d335fb9c4ace61c215f9e0a5d43e0922'
C:\projects\domoticz\extern\jwtcpp\include\jwt-cpp\traits\open-source-parsers-jsoncpp\traits.h(90,44): warning C4244: 'return': conversion from 'Json::Value::Int64' to 'jwt::traits::open_source_parsers_jsoncpp::integer_type', possible loss of data [C:\projects\domoticz\extern\libwebem\webem.vcxproj]
  (compiling source file '/src/cWebem.cpp')

The original warnings;

NotificationFCM.cpp

C:\projects\domoticz\msbuild\Windows Libraries\include\jwt-cpp\jwt.h(2474,48): warning C4244: 'argument': conversion from '_Ty1' to 'const unsigned int', possible loss of data [C:\projects\domoticz\msbuild\domoticz.vcxproj]
C:\projects\domoticz\msbuild\Windows Libraries\include\jwt-cpp\jwt.h(2474,48): warning C4244:         with [C:\projects\domoticz\msbuild\domoticz.vcxproj]
C:\projects\domoticz\msbuild\Windows Libraries\include\jwt-cpp\jwt.h(2474,48): warning C4244:         [ [C:\projects\domoticz\msbuild\domoticz.vcxproj]
C:\projects\domoticz\msbuild\Windows Libraries\include\jwt-cpp\jwt.h(2474,48): warning C4244:             _Ty1=__int64 [C:\projects\domoticz\msbuild\domoticz.vcxproj]
C:\projects\domoticz\msbuild\Windows Libraries\include\jwt-cpp\jwt.h(2474,48): warning C4244:         ] [C:\projects\domoticz\msbuild\domoticz.vcxproj]
  (compiling source file '/notifications/NotificationFCM.cpp')
      C:\projects\domoticz\msbuild\Windows Libraries\include\jwt-cpp\jwt.h(2474,48):
      the template instantiation context (the oldest one first) is
          C:\projects\domoticz\msbuild\Windows Libraries\include\jwt-cpp\traits\kazuho-picojson\defaults.h(19,58):
          see reference to class template instantiation 'jwt::verifier<jwt::default_clock,jwt::traits::kazuho_picojson>' being compiled
          C:\projects\domoticz\msbuild\Windows Libraries\include\jwt-cpp\jwt.h(3706,57):
          see reference to class template instantiation 'jwt::basic_claim<jwt::traits::kazuho_picojson>' being compiled
          C:\projects\domoticz\msbuild\Windows Libraries\include\jwt-cpp\jwt.h(2565,49):
          see reference to class template instantiation 'jwt::details::is_valid_json_types<jwt::traits::kazuho_picojson::value_type,jwt::traits::kazuho_picojson::object_type,jwt::traits::kazuho_picojson::array_type,jwt::traits::kazuho_picojson::string_type,jwt::traits::kazuho_picojson::number_type,jwt::traits::kazuho_picojson::integer_type,jwt::traits::kazuho_picojson::boolean_type>' being compiled
          C:\projects\domoticz\msbuild\Windows Libraries\include\jwt-cpp\jwt.h(2534,74):
          see reference to class template instantiation 'jwt::details::is_valid_json_string<value_type,string_type,integer_type>' being compiled
          with
          [
              value_type=jwt::traits::kazuho_picojson::value_type,
              string_type=jwt::traits::kazuho_picojson::string_type,
              integer_type=jwt::traits::kazuho_picojson::integer_type
          ]
          C:\projects\domoticz\msbuild\Windows Libraries\include\jwt-cpp\jwt.h(2489,35):
          see reference to alias template instantiation 'jwt::details::is_substr_start_end_index_signature<string_type,integer_type>' being compiled
          with
          [
              string_type=jwt::traits::kazuho_picojson::string_type,
              integer_type=jwt::traits::kazuho_picojson::integer_type
          ]
  
C:\projects\domoticz\msbuild\Windows Libraries\include\jwt-cpp\jwt.h(2473,96): warning C4244: 'argument': conversion from '_Ty1' to 'const unsigned int', possible loss of data [C:\projects\domoticz\msbuild\domoticz.vcxproj]
C:\projects\domoticz\msbuild\Windows Libraries\include\jwt-cpp\jwt.h(2473,96): warning C4244:         with [C:\projects\domoticz\msbuild\domoticz.vcxproj]
C:\projects\domoticz\msbuild\Windows Libraries\include\jwt-cpp\jwt.h(2473,96): warning C4244:         [ [C:\projects\domoticz\msbuild\domoticz.vcxproj]
C:\projects\domoticz\msbuild\Windows Libraries\include\jwt-cpp\jwt.h(2473,96): warning C4244:             _Ty1=__int64 [C:\projects\domoticz\msbuild\domoticz.vcxproj]
C:\projects\domoticz\msbuild\Windows Libraries\include\jwt-cpp\jwt.h(2473,96): warning C4244:         ] [C:\projects\domoticz\msbuild\domoticz.vcxproj]
  (compiling source file '/notifications/NotificationFCM.cpp')
  
C:\projects\domoticz\msbuild\Windows Libraries\include\jwt-cpp\jwt.h(2479,96): warning C4244: 'argument': conversion from '_Ty1' to 'const unsigned int', possible loss of data [C:\projects\domoticz\msbuild\domoticz.vcxproj]
C:\projects\domoticz\msbuild\Windows Libraries\include\jwt-cpp\jwt.h(2479,96): warning C4244:         with [C:\projects\domoticz\msbuild\domoticz.vcxproj]
C:\projects\domoticz\msbuild\Windows Libraries\include\jwt-cpp\jwt.h(2479,96): warning C4244:         [ [C:\projects\domoticz\msbuild\domoticz.vcxproj]
C:\projects\domoticz\msbuild\Windows Libraries\include\jwt-cpp\jwt.h(2479,96): warning C4244:             _Ty1=__int64 [C:\projects\domoticz\msbuild\domoticz.vcxproj]
C:\projects\domoticz\msbuild\Windows Libraries\include\jwt-cpp\jwt.h(2479,96): warning C4244:         ] [C:\projects\domoticz\msbuild\domoticz.vcxproj]
  (compiling source file '/notifications/NotificationFCM.cpp')
      C:\projects\domoticz\msbuild\Windows Libraries\include\jwt-cpp\jwt.h(2479,96):
      the template instantiation context (the oldest one first) is
          C:\projects\domoticz\msbuild\Windows Libraries\include\jwt-cpp\jwt.h(2490,14):
          see reference to alias template instantiation 'jwt::details::is_substr_start_index_signature<string_type,integer_type>' being compiled
          with
          [
              string_type=jwt::traits::kazuho_picojson::string_type,
              integer_type=jwt::traits::kazuho_picojson::integer_type
          ]
  
C:\projects\domoticz\msbuild\Windows Libraries\include\jwt-cpp\jwt.h(2635,85): warning C4244: 'argument': conversion from 'double' to '__time64_t', possible loss of data [C:\projects\domoticz\msbuild\domoticz.vcxproj]
  (compiling source file '/notifications/NotificationFCM.cpp')
      C:\projects\domoticz\msbuild\Windows Libraries\include\jwt-cpp\jwt.h(2635,85):
      the template instantiation context (the oldest one first) is
          C:\projects\domoticz\msbuild\Windows Libraries\include\jwt-cpp\traits\kazuho-picojson\defaults.h(19,58):
          see reference to class template instantiation 'jwt::verifier<jwt::default_clock,jwt::traits::kazuho_picojson>' being compiled
          C:\projects\domoticz\msbuild\Windows Libraries\include\jwt-cpp\jwt.h(3706,57):
          see reference to class template instantiation 'jwt::basic_claim<jwt::traits::kazuho_picojson>' being compiled
          C:\projects\domoticz\msbuild\Windows Libraries\include\jwt-cpp\jwt.h(2633,8):
          while compiling class template member function 'jwt::date jwt::basic_claim<jwt::traits::kazuho_picojson>::as_date(void) const'
              C:\projects\domoticz\msbuild\Windows Libraries\include\jwt-cpp\jwt.h(2849,32):
              see the first reference to 'jwt::basic_claim<jwt::traits::kazuho_picojson>::as_date' in 'jwt::payload<json_traits>::get_issued_at'
          with
          [
              json_traits=jwt::traits::kazuho_picojson
          ]
              C:\projects\domoticz\msbuild\Windows Libraries\include\jwt-cpp\jwt.h(3612,24):
              see the first reference to 'jwt::payload<json_traits>::get_issued_at' in 'jwt::verifier<jwt::default_clock,jwt::traits::kazuho_picojson>::{ctor}::<lambda_3d1cddfef0305f90113ebc4bb7c85a28>::operator ()'
          with
          [
              json_traits=jwt::traits::kazuho_picojson
          ]

for the NotificationFCM.cpp there is a change in de domoticz repo;

	{
	const std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
	auto JWT = jwt::create()
		.set_type("JWT")
		.set_issuer(FCMissuer)
		.set_audience(GAPI_OAUTH2_TOKEN_URL)
		.set_issued_at(now)
		.set_expires_at(now + std::chrono::seconds{600})
		.set_payload_claim("scope", jwt::claim(std::string{GAPI_FCM_SCOPE}));
		sFCMjwt = JWT.sign(jwt::algorithm::rs256{"", m_GAPI_FCM_privkey, "", ""}, &base64url_encode);
	}

instead off;

	{
	auto JWT = jwt::create()
		.set_type("JWT")
		.set_issuer(FCMissuer)
		.set_audience(GAPI_OAUTH2_TOKEN_URL)
		.set_issued_at(std::chrono::system_clock::now())
		.set_expires_at(std::chrono::system_clock::now() + std::chrono::seconds{600})
		.set_payload_claim("scope", jwt::claim(std::string{GAPI_FCM_SCOPE}));
		sFCMjwt = JWT.sign(jwt::algorithm::rs256{"", m_GAPI_FCM_privkey, "", ""}, &base64url_encode);
	}

cWebem.cpp

C:\projects\domoticz\msbuild\Windows Libraries\include\jwt-cpp\jwt.h(2474,48): warning C4244: 'argument': conversion from '_Ty1' to 'const unsigned int', possible loss of data [C:\projects\domoticz\msbuild\domoticz.vcxproj]
C:\projects\domoticz\msbuild\Windows Libraries\include\jwt-cpp\jwt.h(2474,48): warning C4244:         with [C:\projects\domoticz\msbuild\domoticz.vcxproj]
C:\projects\domoticz\msbuild\Windows Libraries\include\jwt-cpp\jwt.h(2474,48): warning C4244:         [ [C:\projects\domoticz\msbuild\domoticz.vcxproj]
C:\projects\domoticz\msbuild\Windows Libraries\include\jwt-cpp\jwt.h(2474,48): warning C4244:             _Ty1=__int64 [C:\projects\domoticz\msbuild\domoticz.vcxproj]
C:\projects\domoticz\msbuild\Windows Libraries\include\jwt-cpp\jwt.h(2474,48): warning C4244:         ] [C:\projects\domoticz\msbuild\domoticz.vcxproj]
  (compiling source file '/webserver/cWebem.cpp')
      C:\projects\domoticz\msbuild\Windows Libraries\include\jwt-cpp\jwt.h(2474,48):
      the template instantiation context (the oldest one first) is
          C:\projects\domoticz\msbuild\Windows Libraries\include\jwt-cpp\traits\kazuho-picojson\defaults.h(19,58):
          see reference to class template instantiation 'jwt::verifier<jwt::default_clock,jwt::traits::kazuho_picojson>' being compiled
          C:\projects\domoticz\msbuild\Windows Libraries\include\jwt-cpp\jwt.h(3706,57):
          see reference to class template instantiation 'jwt::basic_claim<jwt::traits::kazuho_picojson>' being compiled
          C:\projects\domoticz\msbuild\Windows Libraries\include\jwt-cpp\jwt.h(2565,49):
          see reference to class template instantiation 'jwt::details::is_valid_json_types<jwt::traits::kazuho_picojson::value_type,jwt::traits::kazuho_picojson::object_type,jwt::traits::kazuho_picojson::array_type,jwt::traits::kazuho_picojson::string_type,jwt::traits::kazuho_picojson::number_type,jwt::traits::kazuho_picojson::integer_type,jwt::traits::kazuho_picojson::boolean_type>' being compiled
          C:\projects\domoticz\msbuild\Windows Libraries\include\jwt-cpp\jwt.h(2534,74):
          see reference to class template instantiation 'jwt::details::is_valid_json_string<value_type,string_type,integer_type>' being compiled
          with
          [
              value_type=jwt::traits::kazuho_picojson::value_type,
              string_type=jwt::traits::kazuho_picojson::string_type,
              integer_type=jwt::traits::kazuho_picojson::integer_type
          ]
          C:\projects\domoticz\msbuild\Windows Libraries\include\jwt-cpp\jwt.h(2489,35):
          see reference to alias template instantiation 'jwt::details::is_substr_start_end_index_signature<string_type,integer_type>' being compiled
          with
          [
              string_type=jwt::traits::kazuho_picojson::string_type,
              integer_type=jwt::traits::kazuho_picojson::integer_type
          ]
  
C:\projects\domoticz\msbuild\Windows Libraries\include\jwt-cpp\jwt.h(2473,96): warning C4244: 'argument': conversion from '_Ty1' to 'const unsigned int', possible loss of data [C:\projects\domoticz\msbuild\domoticz.vcxproj]
C:\projects\domoticz\msbuild\Windows Libraries\include\jwt-cpp\jwt.h(2473,96): warning C4244:         with [C:\projects\domoticz\msbuild\domoticz.vcxproj]
C:\projects\domoticz\msbuild\Windows Libraries\include\jwt-cpp\jwt.h(2473,96): warning C4244:         [ [C:\projects\domoticz\msbuild\domoticz.vcxproj]
C:\projects\domoticz\msbuild\Windows Libraries\include\jwt-cpp\jwt.h(2473,96): warning C4244:             _Ty1=__int64 [C:\projects\domoticz\msbuild\domoticz.vcxproj]
C:\projects\domoticz\msbuild\Windows Libraries\include\jwt-cpp\jwt.h(2473,96): warning C4244:         ] [C:\projects\domoticz\msbuild\domoticz.vcxproj]
  (compiling source file '/webserver/cWebem.cpp')
  
C:\projects\domoticz\msbuild\Windows Libraries\include\jwt-cpp\jwt.h(2479,96): warning C4244: 'argument': conversion from '_Ty1' to 'const unsigned int', possible loss of data [C:\projects\domoticz\msbuild\domoticz.vcxproj]
C:\projects\domoticz\msbuild\Windows Libraries\include\jwt-cpp\jwt.h(2479,96): warning C4244:         with [C:\projects\domoticz\msbuild\domoticz.vcxproj]
C:\projects\domoticz\msbuild\Windows Libraries\include\jwt-cpp\jwt.h(2479,96): warning C4244:         [ [C:\projects\domoticz\msbuild\domoticz.vcxproj]
C:\projects\domoticz\msbuild\Windows Libraries\include\jwt-cpp\jwt.h(2479,96): warning C4244:             _Ty1=__int64 [C:\projects\domoticz\msbuild\domoticz.vcxproj]
C:\projects\domoticz\msbuild\Windows Libraries\include\jwt-cpp\jwt.h(2479,96): warning C4244:         ] [C:\projects\domoticz\msbuild\domoticz.vcxproj]
  (compiling source file '/webserver/cWebem.cpp')
      C:\projects\domoticz\msbuild\Windows Libraries\include\jwt-cpp\jwt.h(2479,96):
      the template instantiation context (the oldest one first) is
          C:\projects\domoticz\msbuild\Windows Libraries\include\jwt-cpp\jwt.h(2490,14):
          see reference to alias template instantiation 'jwt::details::is_substr_start_index_signature<string_type,integer_type>' being compiled
          with
          [
              string_type=jwt::traits::kazuho_picojson::string_type,
              integer_type=jwt::traits::kazuho_picojson::integer_type
          ]
  
C:\projects\domoticz\msbuild\Windows Libraries\include\jwt-cpp\jwt.h(2635,85): warning C4244: 'argument': conversion from 'double' to '__time64_t', possible loss of data [C:\projects\domoticz\msbuild\domoticz.vcxproj]
  (compiling source file '/webserver/cWebem.cpp')
      C:\projects\domoticz\msbuild\Windows Libraries\include\jwt-cpp\jwt.h(2635,85):
      the template instantiation context (the oldest one first) is
          C:\projects\domoticz\msbuild\Windows Libraries\include\jwt-cpp\traits\kazuho-picojson\defaults.h(19,58):
          see reference to class template instantiation 'jwt::verifier<jwt::default_clock,jwt::traits::kazuho_picojson>' being compiled
          C:\projects\domoticz\msbuild\Windows Libraries\include\jwt-cpp\jwt.h(3706,57):
          see reference to class template instantiation 'jwt::basic_claim<jwt::traits::kazuho_picojson>' being compiled
          C:\projects\domoticz\msbuild\Windows Libraries\include\jwt-cpp\jwt.h(2633,8):
          while compiling class template member function 'jwt::date jwt::basic_claim<jwt::traits::kazuho_picojson>::as_date(void) const'
              C:\projects\domoticz\msbuild\Windows Libraries\include\jwt-cpp\jwt.h(2849,32):
              see the first reference to 'jwt::basic_claim<jwt::traits::kazuho_picojson>::as_date' in 'jwt::payload<json_traits>::get_issued_at'
          with
          [
              json_traits=jwt::traits::kazuho_picojson
          ]
              C:\projects\domoticz\msbuild\Windows Libraries\include\jwt-cpp\jwt.h(3612,24):
              see the first reference to 'jwt::payload<json_traits>::get_issued_at' in 'jwt::verifier<jwt::default_clock,jwt::traits::kazuho_picojson>::{ctor}::<lambda_3d1cddfef0305f90113ebc4bb7c85a28>::operator ()'
          with
          [
              json_traits=jwt::traits::kazuho_picojson
          ]

@JurgenLB
Copy link
Contributor Author

JurgenLB commented Mar 8, 2026

// Before (triggered MSVC C4244: implicit int64_t → unsigned int)

using is_substr_start_end_index_signature =
    typename std::is_same<decltype(std::declval<string_type>().substr(
                              std::declval<integer_type>(),
                              std::declval<integer_type>())),
                          string_type>;

// After (explicit cast — no warning, no suppression)

using is_substr_start_end_index_signature =
    typename std::is_same<decltype(std::declval<string_type>().substr(
                              static_cast<std::size_t>(std::declval<integer_type>()),
                              static_cast<std::size_t>(std::declval<integer_type>()))),
                          string_type>;

Same change applied to is_substr_start_index_signature.

// BEFORE: integer_type is Json::Value::Int (32-bit int), but asInt64() returns Int64 (64-bit)
using integer_type = Json::Value::Int;
// ...
case Json::intValue: return val.asInt64(); // C4244: Int64 → Int (data loss)

case Json::intValue: return static_cast<integer_type>(val.asInt64());
or u want
case Json::Value::Int64: return val.asInt64();

// BEFORE: std::round() returns double, from_time_t() expects __time64_t (long long)
return system_clock::from_time_t(std::round(as_number())); // C4244: double → __time64_t

return system_clock::from_time_t(static_cast<std::time_t>(std::round(as_number())));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants