Skip to content

Commit b0a6935

Browse files
committed
[flang] fix Werror=dangling-reference
when compiling with g++ 13.3.0 flang build fails with: llvm-project/flang/lib/Semantics/expression.cpp:424:17: error: possibly dangling reference to a temporary [-Werror=dangling-reference] 424 | const Symbol &coarraySymbol{ref.GetBase().GetLastSymbol()}; | ^~~~~~~~~~~~~ llvm-project/flang/lib/Semantics/expression.cpp:424:58: note: the temporary was destroyed at the end of the full expression ‘Fortran::evaluate::CoarrayRef::GetBase() const().Fortran::evaluate::NamedEntity::GetLastSymbol()’ 424 | const Symbol &coarraySymbol{ref.GetBase().GetLastSymbol()}; | ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~ Keep the base in a temporary variable to make sure it is not deleted.
1 parent a63fd59 commit b0a6935

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

flang/lib/Semantics/expression.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,8 @@ static void CheckSubscripts(
421421

422422
static void CheckSubscripts(
423423
semantics::SemanticsContext &context, CoarrayRef &ref) {
424-
const Symbol &coarraySymbol{ref.GetBase().GetLastSymbol()};
424+
const auto &base = ref.GetBase();
425+
const Symbol &coarraySymbol{base.GetLastSymbol()};
425426
Shape lb, ub;
426427
if (FoldSubscripts(context, coarraySymbol, ref.subscript(), lb, ub)) {
427428
ValidateSubscripts(context, coarraySymbol, ref.subscript(), lb, ub);

0 commit comments

Comments
 (0)