Quantcast
Channel: WE MOVED to github.com/microsoft/cpprestsdk. This site is not monitored!
Viewing all articles
Browse latest Browse all 4845

Commented Issue: Make json::value(const char*) safe under Windows [185]

$
0
0
The following code:

json::value params;
params[U("version")] = json::value("1.0");

results in the following JSON: `{"version":true}` under Windows, as `"1.0"` literal is implicitly converted to `bool` as it's a pointer. This is rather unfortunate and it would be nice to avoid it.

I think the simplest way to solve it would be to add a deleted ctor from narrow strings, i.e.

class value {
#ifdef _UTF16_STRINGS
value(const char*) = delete;
#endif
};

to prevent this code from compiling.

Although personally I'd be even happier if the code accept narrow strings everywhere, even under Windows, and assumed them to be in UTF-8 and did the necessary conversions transparently, this comes at a tiny performance cost but is much more user-friendly.
Comments: Why didn't Artur Laksberg's change on 2013-02-20 making value(bool) constructor explicit didn't fix this? Strange...

Viewing all articles
Browse latest Browse all 4845

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>