[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.
This commit is contained in:
Peter Klausler 2024-08-08 11:08:48 -07:00 committed by GitHub
parent b949a6f5e3
commit 7ea78643fe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 2 additions and 2 deletions

View File

@ -493,7 +493,7 @@ std::optional<Expr<SomeType>> NonPointerInitializationExpr(const Symbol &symbol,
} else {
context.messages().Say(
"Initialization expression for '%s' (%s) cannot be computed as a constant value"_err_en_US,
symbol.name(), folded.AsFortran());
symbol.name(), x.AsFortran());
}
} else if (xType) {
context.messages().Say(

View File

@ -14,7 +14,7 @@ module module1
integer(kind=ik) :: ix = int(0,kind=ik)
real(kind=rk) :: rx = real(0.,kind=rk)
complex(kind=zk) :: zx = cmplx(0.,0.,kind=zk)
!ERROR: Initialization expression for 'cx' (%SET_LENGTH(" ",len)) cannot be computed as a constant value
!ERROR: Initialization expression for 'cx' (" ") cannot be computed as a constant value
character(kind=ck,len=len) :: cx = ' '
logical(kind=lk) :: lx = .false.
real(kind=rk), pointer :: rp => NULL()