From 36078ada02d18feb74e3d548465fc2a00514e20a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolai=20H=C3=A4hnle?= Date: Mon, 7 Oct 2024 21:51:08 +0200 Subject: [PATCH] Silence a warning on gcc 13 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit GCC 13 produced a warning that: .../llvm-dialects/lib/TableGen/Evaluator.cpp:653:31: warning: possibly dangling reference to a temporary [-Wdangling-reference] 653 | const ConstraintSystem &childSystem = logicOr->branches()[i]; | ^~~~~~~~~~~ .../llvm-dialects/lib/TableGen/Evaluator.cpp:653:66: note: the temporary was destroyed at the end of the full expression ‘logicOr->llvm_dialects::LogicOr::branches().llvm::ArrayRef::operator[](((size_t)i))’ 653 | const ConstraintSystem &childSystem = logicOr->branches()[i]; | ^ This warning seems wrong. The temporary ArrayRef returned by LogicOr::branches() is destroyed, yes, but the reference returned by operator[] isn't a reference into the ArrayRef itself, so it shouldn't matter. Oh well. Using a for-each loop is nicer anyway. --- lib/TableGen/Evaluator.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/TableGen/Evaluator.cpp b/lib/TableGen/Evaluator.cpp index 2c82e48..773234b 100644 --- a/lib/TableGen/Evaluator.cpp +++ b/lib/TableGen/Evaluator.cpp @@ -643,14 +643,13 @@ bool Evaluator::checkLogicOr(bool writeErrs, const LogicOr *logicOr) { &m_fmt); } - for (unsigned i = 0; i < logicOr->branches().size(); ++i) { + for (auto [i, childSystem] : llvm::enumerate(logicOr->branches())) { m_out << tgfmt(R"( $_errs << " failed option $0 ($1):\n"; ([&]() { )", &m_fmt, i, logicOr->branchInits()[i]->getAsString()); - const ConstraintSystem &childSystem = logicOr->branches()[i]; Assignment scopedAssignment{&m_assignment}; Evaluator childEvaluator(*m_symbols, scopedAssignment, childSystem, m_out, m_fmt);