From 3acadd98f87210d837bf8016a1fa5b9b375d4f60 Mon Sep 17 00:00:00 2001 From: Peter Klausler Date: Tue, 9 Apr 2024 10:08:11 -0700 Subject: [PATCH] [flang] Don't emit conversion error for max(a,b, optionalCharacter) 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. --- flang/lib/Semantics/check-call.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/flang/lib/Semantics/check-call.cpp b/flang/lib/Semantics/check-call.cpp index bd2f755855172..7d73b55dac328 100644 --- a/flang/lib/Semantics/check-call.cpp +++ b/flang/lib/Semantics/check-call.cpp @@ -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); + } } } }