From 2cc21cecf2478eb71f9ab25f6b7fee7161c3b87b Mon Sep 17 00:00:00 2001 From: Tim Keith Date: Thu, 5 Mar 2020 12:56:30 -0800 Subject: [PATCH] [flang] Change WhyNotModifiable to return optional One overload of WhyNotModifiable returned an optional message while the other returns a unique_ptr. Change the latter to be consistent with the former and other message-returning functions in this file. Also, reorder the if clauses to reduce the level of indentation. Original-commit: flang-compiler/f18@864e9cfc7ee98e3646052fdc757943011d641691 Reviewed-on: https://github.com/flang-compiler/f18/pull/1050 Tree-same-pre-rewrite: false --- flang/include/flang/Semantics/tools.h | 2 +- flang/lib/Semantics/check-call.cpp | 7 +++--- flang/lib/Semantics/tools.cpp | 32 +++++++++++---------------- 3 files changed, 17 insertions(+), 24 deletions(-) diff --git a/flang/include/flang/Semantics/tools.h b/flang/include/flang/Semantics/tools.h index 0dd43a281c06..e2179075e087 100644 --- a/flang/include/flang/Semantics/tools.h +++ b/flang/include/flang/Semantics/tools.h @@ -167,7 +167,7 @@ bool IsAssumedLengthExternalCharacterFunction(const Symbol &); // Is the symbol modifiable in this scope std::optional WhyNotModifiable( const Symbol &, const Scope &); -std::unique_ptr WhyNotModifiable(SourceName, const SomeExpr &, +std::optional WhyNotModifiable(SourceName, const SomeExpr &, const Scope &, bool vectorSubscriptIsOk = false); const Symbol *IsExternalInPureContext(const Symbol &, const Scope &); bool HasCoarray(const parser::Expr &); diff --git a/flang/lib/Semantics/check-call.cpp b/flang/lib/Semantics/check-call.cpp index bca65e9909b7..3273ed22da40 100644 --- a/flang/lib/Semantics/check-call.cpp +++ b/flang/lib/Semantics/check-call.cpp @@ -329,13 +329,12 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy, } if (reason && scope) { bool vectorSubscriptIsOk{isElemental || dummyIsValue}; // 15.5.2.4(21) - std::unique_ptr why{ - WhyNotModifiable(messages.at(), actual, *scope, vectorSubscriptIsOk)}; - if (why.get()) { + if (auto why{WhyNotModifiable( + messages.at(), actual, *scope, vectorSubscriptIsOk)}) { if (auto *msg{messages.Say( "Actual argument associated with %s %s must be definable"_err_en_US, reason, dummyName)}) { - msg->Attach(std::move(why)); + msg->Attach(*why); } } } diff --git a/flang/lib/Semantics/tools.cpp b/flang/lib/Semantics/tools.cpp index 922f38f44d0b..de9131d8f86b 100644 --- a/flang/lib/Semantics/tools.cpp +++ b/flang/lib/Semantics/tools.cpp @@ -789,29 +789,23 @@ std::optional WhyNotModifiable( } } -std::unique_ptr WhyNotModifiable(parser::CharBlock at, +std::optional WhyNotModifiable(parser::CharBlock at, const SomeExpr &expr, const Scope &scope, bool vectorSubscriptIsOk) { - if (evaluate::IsVariable(expr)) { - if (auto dataRef{evaluate::ExtractDataRef(expr)}) { - if (!vectorSubscriptIsOk && evaluate::HasVectorSubscript(expr)) { - return std::make_unique( - at, "variable has a vector subscript"_en_US); - } else { - const Symbol &symbol{dataRef->GetFirstSymbol()}; - if (auto maybeWhy{WhyNotModifiable(symbol, scope)}) { - return std::make_unique(symbol.name(), - parser::MessageFormattedText{ - std::move(*maybeWhy), symbol.name()}); - } - } - } else { - // reference to function returning POINTER + if (!evaluate::IsVariable(expr)) { + return parser::Message{at, "Expression is not a variable"_en_US}; + } else if (auto dataRef{evaluate::ExtractDataRef(expr)}) { + if (!vectorSubscriptIsOk && evaluate::HasVectorSubscript(expr)) { + return parser::Message{at, "Variable has a vector subscript"_en_US}; + } + const Symbol &symbol{dataRef->GetFirstSymbol()}; + if (auto maybeWhy{WhyNotModifiable(symbol, scope)}) { + return parser::Message{symbol.name(), + parser::MessageFormattedText{std::move(*maybeWhy), symbol.name()}}; } } else { - return std::make_unique( - at, "expression is not a variable"_en_US); + // reference to function returning POINTER } - return {}; + return std::nullopt; } class ImageControlStmtHelper {