Skip to content

Commit f059017

Browse files
authored
[flang] Silence an inappropriate warning (#104685)
A bare ALLOCATE statement with no SOURCE= rightly earns a warning about an undefined function result, if that result is an allocatable that appears in the ALLOCATE. But in the case of a pointer, where the warning should care more about the pointer's association status than the value of its target, a bare ALLOCATE should suffice to silence the warning.
1 parent 90d753a commit f059017

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

flang/lib/Semantics/definable.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ static std::optional<parser::Message> WhyNotDefinableBase(parser::CharBlock at,
127127
(!IsPointer(ultimate) || (isWholeSymbol && isPointerDefinition))) {
128128
return BlameSymbol(
129129
at, "'%s' is an INTENT(IN) dummy argument"_en_US, original);
130-
} else if (acceptAllocatable &&
130+
} else if (acceptAllocatable && IsAllocatable(ultimate) &&
131131
!flags.test(DefinabilityFlag::SourcedAllocation)) {
132132
// allocating a function result doesn't count as a def'n
133133
// unless there's SOURCE=

flang/test/Semantics/undef-result01.f90

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ function basicAlloc()
4444
allocate(basicAlloc)
4545
end
4646

47+
function allocPtr()
48+
real, pointer :: allocPtr
49+
allocate(allocPtr) ! good enough for pointer
50+
end
51+
4752
function sourcedAlloc()
4853
real, allocatable :: sourcedAlloc
4954
allocate(sourcedAlloc, source=0.)

0 commit comments

Comments
 (0)