[ https://issues.apache.org/jira/browse/PROTON-1216?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15311188#comment-15311188 ]
Alan Conway commented on PROTON-1216: ------------------------------------- Committed approved bits to 0.13.x: b30fa9c PROTON-1216: c++: cleanup to previous commit. 68f1c15 PROTON-1216: c++: proton::coerce should convert binary to string. Fixed windows warnings on master, almost 0 risk - conditionally disabled one warning for one line of code. Will add to 0.13.x if approved. {code} diff --git a/proton-c/bindings/cpp/include/proton/internal/type_traits.hpp b/proton-c/bindings/cpp/include/proton/internal/type_traits.hpp index 0490823..c99c248 100644 --- a/proton-c/bindings/cpp/include/proton/internal/type_traits.hpp +++ b/proton-c/bindings/cpp/include/proton/internal/type_traits.hpp @@ -161,7 +161,17 @@ template <class From, class To> struct is_convertible : public sfinae { static yes test(const To&); static no test(...); static const From& from; + // Windows compilers warn about data-loss caused by legal conversions. We + // can't use static_cast because that will cause a hard error instead of + // letting SFINAE overload resolution select the test(...) overload. +#ifdef _WIN32 +#pragma warning( push ) +#pragma warning( disable : 4244 ) +#endif static bool const value = sizeof(test(from)) == sizeof(yes); +#ifdef _WIN32 +#pragma warning( pop ) +#endif }; {code} > c++: proton::coerce<std::string>() should allow conversion from binary. > ----------------------------------------------------------------------- > > Key: PROTON-1216 > URL: https://issues.apache.org/jira/browse/PROTON-1216 > Project: Qpid Proton > Issue Type: Bug > Components: cpp-binding > Affects Versions: 0.12.2 > Reporter: Alan Conway > Assignee: Alan Conway > Fix For: 0.13.0 > > > proton::coerce<std::string> should convert a binary value to a std::string. > The documentation also needs clarification: coerce should allow exactly those > conversions that are allowed as implicit C++ conversions. > Issue raised in excellent bug report on the user list > http://qpid.2158936.n2.nabble.com/Proton-C-0-13-x-decode-binary-type-tp7644510p7644747.html > text follows: > proton::coerce (both forms) currently throws the same > exception as proton::get, as does value.as_string(), although that doesn't > appear to be in the public API. Not sure what 'd' was in the d>>b example, > but got a version working using value.get<std::binary>() and an implicit > cast to std::string. > To reproduce... > #include <proton/value.hpp> > #include <proton/binary.hpp> > #include <proton/error.hpp> > #include <iostream> > template<typename Lambda> > void expect_exception ( Lambda f ) > { > try > { > f(); > std::cout << "*** FAIL (expected conversion error) ***" << std::endl; > } > catch ( const proton::conversion_error& e ) > { > std::cout << "PASS" << std::endl; > } > } > template<typename Lambda> > void expect_value ( const std::string& expected, Lambda f ) > { > try > { > std::cout << (f() == expected ? "PASS" : "*** FAIL (wrong value) ***") > << std::endl; > } > catch ( const proton::conversion_error& e ) > { > std::cout << "*** FAIL (conversion error) ***" << std::endl; > } > } > int main() > { > std::string expected = "Hello World!"; > proton::value value = proton::binary(expected); > expect_exception( [=] { return value.get<std::string>(); > > }); > expect_exception( [=] { return proton::get<std::string>(value); > > }); > expect_exception( [=] { std::string result; > proton::get<std::string>(value); return result; }); > expect_value(expected, [=] () -> std::string { return > value.get<proton::binary>(); } ); > // The following currently fail under 0.13.x > expect_value(expected, [=] { return value.as_string(); > > }); > expect_value(expected, [=] { return proton::coerce<std::string>(value); > > }); > expect_value(expected, [=] { std::string result; > proton::coerce<std::string>(value, result); return result; }); > > } -- This message was sent by Atlassian JIRA (v6.3.4#6332) --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@qpid.apache.org For additional commands, e-mail: dev-h...@qpid.apache.org