Skip to content

Commit e8572d0

Browse files
authored
[flang] Don't emit conversion error for max(a,b, optionalCharacter) (#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.
1 parent 14e6f63 commit e8572d0

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

flang/lib/Semantics/check-call.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,10 +1477,15 @@ static void CheckMaxMin(const characteristics::Procedure &proc,
14771477
if (arguments[j]) {
14781478
if (const auto *expr{arguments[j]->UnwrapExpr()};
14791479
expr && evaluate::MayBePassedAsAbsentOptional(*expr)) {
1480-
if (auto thisType{expr->GetType()};
1481-
thisType && *thisType != typeAndShape->type()) {
1482-
messages.Say(arguments[j]->sourceLocation(),
1483-
"An actual argument to MAX/MIN requiring data conversion may not be OPTIONAL, POINTER, or ALLOCATABLE"_err_en_US);
1480+
if (auto thisType{expr->GetType()}) {
1481+
if (thisType->category() == TypeCategory::Character &&
1482+
typeAndShape->type().category() == TypeCategory::Character &&
1483+
thisType->kind() == typeAndShape->type().kind()) {
1484+
// don't care about lengths
1485+
} else if (*thisType != typeAndShape->type()) {
1486+
messages.Say(arguments[j]->sourceLocation(),
1487+
"An actual argument to MAX/MIN requiring data conversion may not be OPTIONAL, POINTER, or ALLOCATABLE"_err_en_US);
1488+
}
14841489
}
14851490
}
14861491
}

0 commit comments

Comments
 (0)