Gerrit0 commented on code in PR #2931: URL: https://github.com/apache/avro/pull/2931#discussion_r1622600509
########## lang/c++/impl/Compiler.cc: ########## @@ -286,8 +286,9 @@ static Field makeField(const Entity &e, SymbolTable &st, const string &ns) { const Object &m = e.objectValue(); string n = getStringField(e, m, "name"); vector<string> aliases; - if (containsField(m, "aliases")) { - for (const auto &alias : getArrayField(e, m, "aliases")) { + string aliasesName = "aliases"; + if (containsField(m, aliasesName)) { + for (const auto &alias : getArrayField(e, m, aliasesName)) { Review Comment: I'll admit this is kind of a weird change... the compiler appears to think that the lifetime of the name passed to `getArrayField` may be linked to the lifetime of the returned reference. It doesn't appear to be from my investigation, but this happens to slightly improve performance wherever we use `containsField` + `getArrayField` together anyways, so seems a minor cost to pay. ```text /home/gerrit/Desktop/avro/lang/c++/impl/Compiler.cc: In function ‘avro::Field avro::makeField(const json::Entity&, SymbolTable&, const std::string&)’: /home/gerrit/Desktop/avro/lang/c++/impl/Compiler.cc:290:63: error: possibly dangling reference to a temporary [-Werror=dangling-reference] 290 | for (const auto &alias : getArrayField(e, m, "aliases")) { | ^ /home/gerrit/Desktop/avro/lang/c++/impl/Compiler.cc:290:47: note: the temporary was destroyed at the end of the full expression ‘avro::getArrayField((* & e), (* & m), std::__cxx11::basic_string<char>(((const char*)"aliases"), std::allocator<char>()))’ 290 | for (const auto &alias : getArrayField(e, m, "aliases")) { | ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~ ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@avro.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org