-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
::get<int>() fails in new(er) release [MSVC] #780
Comments
How does |
that is the latest develop version.
values is just an array of 4 numbers, nothing special. but this is all compile time, so the actual contents of values is only hypothetical. sorry, forgot to add that the function is a class constructor. the main reason I updated from the previous release I was running, is that I couldn't serialize BYTE (__uint8) or obvious char/__int8 values. But I thought it best to see if that had been addresses in a more recent commit before searching issues. |
Here's a complete-ish copy of the class header: struct hsv_t {
int h;
int s;
int v;
int a;
constexpr hsv_t() : h(0), s(0), v(0), a(0) {}
constexpr hsv_t(int h, int s, int v, int a) : h(wrap360(h)), s(clamp100(s)), v(clamp100(v)), a(clamp255(a)){}
constexpr hsv_t(int h, int s, int v) : hsv_t(h, s, v, 255) {}
constexpr hsv_t(float h, float s, float v) : hsv_t(h * 360, s * 100, v * 100, 255) {}
template<typename T>
constexpr hsv_t(T (&values)[3])
: hsv_t(
static_cast<int>(values[0]),
static_cast<int>(values[1]),
static_cast<int>(values[2])){}
template<typename T>
constexpr hsv_t(T (&values)[4])
: hsv_t(
static_cast<int>(values[0]),
static_cast<int>(values[1]),
static_cast<int>(values[2]),
static_cast<int>(values[3])){}
template<typename T>
constexpr hsv_t(std::array<T, 4> values)
: hsv_t(
static_cast<int>(values[0]),
static_cast<int>(values[1]),
static_cast<int>(values[2]),
static_cast<int>(values[3])){}
hsv_t(const json &values)
: hsv_t(
wrap360( values[0].get<int>()),
clamp100(values[1].get<int>()),
clamp100(values[2].get<int>()),
clamp100(values[3].get<int>())){} There's probably a fancy way to cast the I should add, that this isn't the only place the error occurred, simply the first place. I can make you a test project for MSVC if you like. |
What is |
LOL, I really should have looked for a simpler instance, in-fact, I will do exactly that. It's dealing with the HSV color palette, so template <typename T>
constexpr uint8_t clamp100(T val) {
#define MIN 0
#define MAX 100
return (
val > MAX ? MAX :
val < MIN ? MIN :
val
);
#undef MIN
#undef MAX
}
template <typename T>
constexpr uint16_t wrap360(T val) {
#define MIN 0
#define MAX 360
return (
(val + MAX) % MAX
);
#undef MIN
#undef MAX
} I did find out something new though -- because the constructor taking std::vector<int> v{1, 2, 3};
rgb_t color = rgb_t(v); was passed through the The constructor is marked |
Hmmm.... turns out, there is no simpler instance of it failing. Just the I did remove the misc. clamps, and such, and used the original explicit hsv_t(const json &values)
: hsv_t(
values[0].get<int>(),
values[1].get<int>(),
values[2].get<int>(),
values[3].get<int>()
){} The errors are repeated for each of the 4 lines of the constructor.
I was especially thrown by |
Okay, I went hunting for other occurrences of These weren't immediately apparent, because the compiler halts after the errors above. "No instance of overloaded function basic_json... matches the argument list. Object type is: json" if (j.is_string()) {
result = getTextFromLabel(ptr, j.get<std::string>().c_str()); "No instance of overloaded function basic_json... matches the argument list. Object type is: basic_json<std::map ... adl_serializer>" for (int ii = 0; ii < a.size(); ii++) {
// Let keep it simple for demonstration purposes:
printf("%i", a[ii].get<int>());
} |
This is very strange, I've seen some projects like sqlpp11 that were broken by the latest MSVC 2017 release... Might it be the case here? |
Just tested a compile using the 2015 command line tools, same result. Interestingly, a quick test program which should have caused the same error, compiled without issue. confused #include "json.hpp"
using json = nlohmann::json;
int main(int argc, char **argv) {
json j = { {"list", {1, 0, 2} } };
json j2 = j["list"];
auto item = j2[1].get<int>();
} A quick google search on the error message produced (apart from this issue) an article about constexpr causing issues. |
This really sounds like a bug. Did you try (just to make sure) to remove the |
From your snippet, it seems like there's a bug in your macro. Did you forget the double quotes?
|
No, |
I am not sure whether I can help with #780 (comment), especially without knowing how |
There are no |
@gregmarr yes, that's was implied by my statement "one of the structs for which I have a to_json helper defined" @nlohmann I wouldn't expect you to. And, it's another issue anyway. I think I should just delete that last comment regarding the error, and |
Just tested the same commit that had the failing "get()" code in it, with the same compiler and platform toolset, (MSVC140) but with the latest json.hpp, and it compiled without issue. So I then checked out the latest version of our project, copied the latest json.hpp in, and compiled it with the newest MSVC141/C++17 and it also compiled without issue. So, I think we can call that resolved. |
Is anybody else still having a problem with this? In Visual Studio 15.6.4, I'm unable to compile the following example: #include "json.hpp"
namespace quicktype {
using nlohmann::json;
struct TestSchema {
double test_val;
};
inline json get_untyped(const json &j, const char *property) {
if (j.find(property) != j.end()) {
return j.at(property).get<json>();
}
return json();
}
}
namespace nlohmann {
inline void from_json(const json& _j, struct quicktype::TestSchema& _x) {
_x.test_val = _j.at("test_val").get<double>();
}
inline void to_json(json& _j, const struct quicktype::TestSchema& _x) {
_j = json::object();
_j["test_val"] = _x.test_val;
}
} The error messages are:
It seems pretty clearly to be a failure on Visual Studio's C++11 support, but I'm curious if there's any known workaround, since people further up in the thread seemed to have found success. |
I don't know if that will help, but you really should not add free functions in the Could you put the |
Thanks, @theodelrieu -- that did indeed solve my problem. I misunderstood the docs about where the |
Glad to hear :) |
Hello sfinktah! |
Compiler: MSVC 15.1 (2017) with VS2015 libraries etc.
Was working with: c42273d (2.1.1)
Fails with: d300a8e (2.1.1) latest dev
But error just moved to json.hpp +9836
The text was updated successfully, but these errors were encountered: