Skip to content

Commit 143be4e

Browse files
authored
[flang] Silence spurious error (#104821)
Don't complain about a local object with an impure final procedure in a pure subprogram when the local object is a named constant. Fixes #104796.
1 parent f059017 commit 143be4e

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

flang/lib/Semantics/tools.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,8 +1558,9 @@ bool IsAutomaticallyDestroyed(const Symbol &symbol) {
15581558
return symbol.has<ObjectEntityDetails>() &&
15591559
(symbol.owner().kind() == Scope::Kind::Subprogram ||
15601560
symbol.owner().kind() == Scope::Kind::BlockConstruct) &&
1561-
(!IsDummy(symbol) || IsIntentOut(symbol)) && !IsPointer(symbol) &&
1562-
!IsSaved(symbol) && !FindCommonBlockContaining(symbol);
1561+
!IsNamedConstant(symbol) && (!IsDummy(symbol) || IsIntentOut(symbol)) &&
1562+
!IsPointer(symbol) && !IsSaved(symbol) &&
1563+
!FindCommonBlockContaining(symbol);
15631564
}
15641565

15651566
const std::optional<parser::Name> &MaybeGetNodeName(

flang/test/Semantics/declarations05.f90

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ pure subroutine test
2929
type(t1) x1
3030
!WARNING: 'x1a' of derived type 't1' does not have a FINAL subroutine for its rank (1)
3131
type(t1), allocatable :: x1a(:)
32+
type(t1), parameter :: namedConst = t1() ! ok
3233
!ERROR: 'x2' may not be a local variable in a pure subprogram
3334
!BECAUSE: 'x2' has an impure FINAL procedure 'final'
3435
type(t2) x2

0 commit comments

Comments
 (0)