diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp index a62b7c36fe61f..0aca2cddb953f 100644 --- a/flang/lib/Semantics/resolve-names.cpp +++ b/flang/lib/Semantics/resolve-names.cpp @@ -235,7 +235,7 @@ class AttrsVisitor : public virtual BaseVisitor { Attrs GetAttrs(); Attrs EndAttrs(); bool SetPassNameOn(Symbol &); - bool SetBindNameOn(Symbol &); + void SetBindNameOn(Symbol &); void Post(const parser::LanguageBindingSpec &); bool Pre(const parser::IntentSpec &); bool Pre(const parser::Pass &); @@ -1529,28 +1529,26 @@ bool AttrsVisitor::SetPassNameOn(Symbol &symbol) { return true; } -bool AttrsVisitor::SetBindNameOn(Symbol &symbol) { +void AttrsVisitor::SetBindNameOn(Symbol &symbol) { if (!attrs_ || !attrs_->test(Attr::BIND_C)) { - return false; + return; } std::optional label{evaluate::GetScalarConstantValue< evaluate::Type>(bindName_)}; // 18.9.2(2): discard leading and trailing blanks, ignore if all blank if (label) { auto first{label->find_first_not_of(" ")}; - auto last{label->find_last_not_of(" ")}; if (first == std::string::npos) { + // Empty NAME= means no binding at all (18.10.2p2) Say(currStmtSource().value(), "Blank binding label ignored"_en_US); - label.reset(); - } else { - label = label->substr(first, last - first + 1); + return; } - } - if (!label) { + auto last{label->find_last_not_of(" ")}; + label = label->substr(first, last - first + 1); + } else { label = parser::ToLowerCaseLetters(symbol.name().ToString()); } symbol.SetBindName(std::move(*label)); - return true; } void AttrsVisitor::Post(const parser::LanguageBindingSpec &x) {