Skip to content

Commit

Permalink
[flang] Don't emit conversion error for max(a,b, optionalCharacter) (#…
Browse files Browse the repository at this point in the history
…88156)

A recent patch added an error message for whole optional dummy argument
usage as optional arguments (third or later) to MAX and MIN when those
names required type conversion, since that conversion only works when
the optional arguments are present. This check shouldn't care about
character lengths. Make it so.
  • Loading branch information
klausler committed Apr 22, 2024
1 parent 14e6f63 commit e8572d0
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions flang/lib/Semantics/check-call.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1477,10 +1477,15 @@ static void CheckMaxMin(const characteristics::Procedure &proc,
if (arguments[j]) {
if (const auto *expr{arguments[j]->UnwrapExpr()};
expr && evaluate::MayBePassedAsAbsentOptional(*expr)) {
if (auto thisType{expr->GetType()};
thisType && *thisType != typeAndShape->type()) {
messages.Say(arguments[j]->sourceLocation(),
"An actual argument to MAX/MIN requiring data conversion may not be OPTIONAL, POINTER, or ALLOCATABLE"_err_en_US);
if (auto thisType{expr->GetType()}) {
if (thisType->category() == TypeCategory::Character &&
typeAndShape->type().category() == TypeCategory::Character &&
thisType->kind() == typeAndShape->type().kind()) {
// don't care about lengths
} else if (*thisType != typeAndShape->type()) {
messages.Say(arguments[j]->sourceLocation(),
"An actual argument to MAX/MIN requiring data conversion may not be OPTIONAL, POINTER, or ALLOCATABLE"_err_en_US);
}
}
}
}
Expand Down

0 comments on commit e8572d0

Please sign in to comment.