Commit 7c40f03a authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook GitHub Bot

address warning C4866 in bser

Summary:
Fixes this warning:

```
folly\experimental\bser\Load.cpp(109) : warning C4866: compiler may not enforce left-to-right evaluation order for call to 'folly::dynamic::operator[]'
folly\experimental\bser\Load.cpp(131) : warning C4866: compiler may not enforce left-to-right evaluation order for call to 'folly::dynamic::operator[]'
folly\experimental\bser\Load.cpp(136) : warning C4866: compiler may not enforce left-to-right evaluation order for call to 'folly::dynamic::operator[]'
```

Reviewed By: luciang

Differential Revision: D31320782

fbshipit-source-id: 9e42176436d7ebf22af38b0589ccdc75e020b771
parent d8d384e1
...@@ -24,6 +24,8 @@ ...@@ -24,6 +24,8 @@
namespace folly { namespace folly {
using namespace string_piece_literals;
namespace { namespace {
folly::dynamic& insertAtKey( folly::dynamic& insertAtKey(
folly::dynamic* d, bool allow_non_string_keys, const folly::dynamic& key) { folly::dynamic* d, bool allow_non_string_keys, const folly::dynamic& key) {
...@@ -31,7 +33,13 @@ folly::dynamic& insertAtKey( ...@@ -31,7 +33,13 @@ folly::dynamic& insertAtKey(
return (*d)[key]; return (*d)[key];
} else if (key.isNumber() || key.isBool()) { } else if (key.isNumber() || key.isBool()) {
// folly::dynamic allows non-null scalars for keys. // folly::dynamic allows non-null scalars for keys.
return allow_non_string_keys ? (*d)[key] : (*d)[key.asString()]; if (allow_non_string_keys) {
return (*d)[key];
} else {
auto keyc = key.asString();
auto keyv = StringPiece(keyc); // to evade MSVC C4866
return (*d)[keyv];
}
} }
// One cause might be oddness like p.optional(dynamic::array(...), ...); // One cause might be oddness like p.optional(dynamic::array(...), ...);
throw DynamicParserLogicError( throw DynamicParserLogicError(
...@@ -67,16 +75,16 @@ void DynamicParser::reportError( ...@@ -67,16 +75,16 @@ void DynamicParser::reportError(
} else { } else {
// The e["value"].isNull() trick cannot be used because value().type() // The e["value"].isNull() trick cannot be used because value().type()
// *can* be folly::dynamic::Type::NULLT, so we must hash again. // *can* be folly::dynamic::Type::NULLT, so we must hash again.
e["value"] = value(); e["value"_sp] = value();
} }
// Differentiate between "parsing value" and "looking up key" errors. // Differentiate between "parsing value" and "looking up key" errors.
auto& e_msg = [&]() -> folly::dynamic& { auto& e_msg = [&]() -> folly::dynamic& {
if (lookup_k == nullptr) { // {object,array}Items, or post-key-lookup if (lookup_k == nullptr) { // {object,array}Items, or post-key-lookup
return e["error"]; return e["error"_sp];
} }
// Multiple key lookups can report errors on the same collection. // Multiple key lookups can report errors on the same collection.
auto& key_errors = e["key_errors"]; auto& key_errors = e["key_errors"_sp];
if (key_errors.isNull()) { if (key_errors.isNull()) {
// Treat arrays as integer-keyed objects. // Treat arrays as integer-keyed objects.
key_errors = folly::dynamic::object(); key_errors = folly::dynamic::object();
...@@ -136,7 +144,7 @@ folly::dynamic& DynamicParser::ParserStack::errors( ...@@ -136,7 +144,7 @@ folly::dynamic& DynamicParser::ParserStack::errors(
// Materialize the lazy "key + parent's type" error objects we'll need. // Materialize the lazy "key + parent's type" error objects we'll need.
CHECK(!subErrors_.empty()) << "Internal bug: out of suberrors"; CHECK(!subErrors_.empty()) << "Internal bug: out of suberrors";
for (const auto& suberror_key : unmaterializedSubErrorKeys_) { for (const auto& suberror_key : unmaterializedSubErrorKeys_) {
auto& nested = (*subErrors_.back())["nested"]; auto& nested = (*subErrors_.back())["nested"_sp];
if (nested.isNull()) { if (nested.isNull()) {
nested = folly::dynamic::object(); nested = folly::dynamic::object();
} }
......
...@@ -106,7 +106,8 @@ static dynamic decodeObject(Cursor& curs) { ...@@ -106,7 +106,8 @@ static dynamic decodeObject(Cursor& curs) {
throwDecodeError(curs, "expected String"); throwDecodeError(curs, "expected String");
} }
auto key = decodeString(curs); auto key = decodeString(curs);
obj[key] = parseBser(curs); auto keyv = StringPiece(key); // to evade MSVC C4866
obj[keyv] = parseBser(curs);
} }
return obj; return obj;
} }
...@@ -126,14 +127,15 @@ static dynamic decodeTemplate(Cursor& curs) { ...@@ -126,14 +127,15 @@ static dynamic decodeTemplate(Cursor& curs) {
dynamic obj = dynamic::object; dynamic obj = dynamic::object;
for (auto& name : names) { for (auto& name : names) {
StringPiece keyv = name.getString(); // to evade MSVC C4866
auto bytes = curs.peekBytes(); auto bytes = curs.peekBytes();
if ((BserType)bytes.at(0) == BserType::Skip) { if ((BserType)bytes.at(0) == BserType::Skip) {
obj[name.getString()] = nullptr; obj[keyv] = nullptr;
curs.skipAtMost(1); curs.skipAtMost(1);
continue; continue;
} }
obj[name.getString()] = parseBser(curs); obj[keyv] = parseBser(curs);
} }
arr.push_back(std::move(obj)); arr.push_back(std::move(obj));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment