You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When serialising an enum value not covered by JSONCONS_ENUM_NAME_TRAITS, I expect an exception to be thrown that the application can catch and then carry on. That works with a bare enum value, but not if the enum value is inside a struct. In that case, the program crashes with SIGABRT signal:
terminate called after throwing an instance of 'jsoncons::conv_error'what(): Not an enum: Unable to convert into the provided type
Aborted (core dumped)
This program reproduces the issue:
#include<iostream>
#include<jsoncons/json.hpp>enumclassMyEnum { A, B };
structMyStruct {
MyEnum x;
};
intmain() {
// Prints "Exception: Not an enum: Unable to convert into the provided type" and continues programtry {
jsoncons::encode_json(MyEnum::B, std::cout);
} catch (const jsoncons::json_exception &e) {
std::cout << "Exception: " << e.what() << std::endl;
}
/* * SIGABRT, exception is not caught. Prints: * terminate called after throwing an instance of 'jsoncons::conv_error' * what(): Not an enum: Unable to convert into the provided type * Aborted (core dumped)*/try {
jsoncons::encode_json(MyStruct {MyEnum::B}, std::cout);
} catch (const jsoncons::conv_error &e) {
std::cout << "Exception: " << e.what() << std::endl;
} catch (const jsoncons::json_exception &e) {
std::cout << "Exception: " << e.what() << std::endl;
} catch (...) {
std::cout << "Something else caught" << std::endl;
}
return0;
}
JSONCONS_ALL_MEMBER_TRAITS(MyStruct, x);
JSONCONS_ENUM_NAME_TRAITS(MyEnum, (A, "A")); // B is missing
When serialising an enum value not covered by
JSONCONS_ENUM_NAME_TRAITS
, I expect an exception to be thrown that the application can catch and then carry on. That works with a bare enum value, but not if the enum value is inside a struct. In that case, the program crashes with SIGABRT signal:This program reproduces the issue:
What jsoncons library version?
The text was updated successfully, but these errors were encountered: