Skip to content

Commit 7ea7864

Browse files
authored
[flang] Improve error message output (#102324)
When a local character variable with non-constant length has an initializer, it's an error in a couple of ways (SAVE variable with unknown size, static initializer that isn't constant due to conversion to an unknown length). The error that f18 reports is the latter, but the message contains a formatted representation of the initialization expression that exposes a non-Fortran %SET_LENGTH() operation. Print the original expression in the message instead.
1 parent b949a6f commit 7ea7864

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

flang/lib/Evaluate/check-expression.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ std::optional<Expr<SomeType>> NonPointerInitializationExpr(const Symbol &symbol,
493493
} else {
494494
context.messages().Say(
495495
"Initialization expression for '%s' (%s) cannot be computed as a constant value"_err_en_US,
496-
symbol.name(), folded.AsFortran());
496+
symbol.name(), x.AsFortran());
497497
}
498498
} else if (xType) {
499499
context.messages().Say(

flang/test/Semantics/structconst02.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ end function realfunc
1414
integer(kind=ik) :: ix = int(0,kind=ik)
1515
real(kind=rk) :: rx = real(0.,kind=rk)
1616
complex(kind=zk) :: zx = cmplx(0.,0.,kind=zk)
17-
!ERROR: Initialization expression for 'cx' (%SET_LENGTH(" ",len)) cannot be computed as a constant value
17+
!ERROR: Initialization expression for 'cx' (" ") cannot be computed as a constant value
1818
character(kind=ck,len=len) :: cx = ' '
1919
logical(kind=lk) :: lx = .false.
2020
real(kind=rk), pointer :: rp => NULL()

0 commit comments

Comments
 (0)