diff --git a/flang/lib/common/template.h b/flang/lib/common/template.h index e55e95ffd546..2c88bd461398 100644 --- a/flang/lib/common/template.h +++ b/flang/lib/common/template.h @@ -267,7 +267,7 @@ std::optional> AllPresent(std::optional &&... x) { // N.B. If the function returns std::optional, MapOptional will return // std::optional> and you will probably want to // run it through JoinOptional to "squash" it. -template +template std::optional MapOptional( std::function &&f, std::optional &&... x) { if (auto args{AllPresent(std::move(x)...)}) { @@ -275,7 +275,7 @@ std::optional MapOptional( } return std::nullopt; } -template +template std::optional MapOptional(R (*f)(A &&...), std::optional &&... x) { return MapOptional(std::function{f}, std::move(x)...); } diff --git a/flang/lib/parser/message.h b/flang/lib/parser/message.h index 7d666318c28c..fbe97bb2ae92 100644 --- a/flang/lib/parser/message.h +++ b/flang/lib/parser/message.h @@ -151,9 +151,8 @@ public: attachmentIsContext_ = true; } Message &Attach(Message *); - template - Message &Attach(A &&... args) { - return Attach(new Message{std::move(args)...}); // reference-counted + template Message &Attach(A &&... args) { + return Attach(new Message{std::forward(args)...}); // reference-counted } bool SortBefore(const Message &that) const; @@ -206,7 +205,7 @@ public: bool empty() const { return messages_.empty(); } template Message &Say(A... args) { - last_ = messages_.emplace_after(last_, args...); + last_ = messages_.emplace_after(last_, std::forward(args)...); return *last_; } @@ -254,17 +253,16 @@ public: return common::ScopedSet(at_, std::move(at)); } - template - Message *Say(CharBlock at, A &&... args) { + template Message *Say(CharBlock at, A &&... args) { if (messages_ != nullptr) { - return &messages_->Say(at, std::move(args)...); + return &messages_->Say(at, std::forward(args)...); } else { return nullptr; } } - template Message *Say(A &&... args) { - return Say(at_, std::move(args)...); + template Message *Say(A &&... args) { + return Say(at_, std::forward(args)...); } private: diff --git a/flang/lib/parser/parse-state.h b/flang/lib/parser/parse-state.h index 15e25f77d248..65ec9ec371b2 100644 --- a/flang/lib/parser/parse-state.h +++ b/flang/lib/parser/parse-state.h @@ -143,18 +143,19 @@ public: context_ = context_->attachment(); } - template void Say(CharBlock range, A... args) { + template void Say(CharBlock range, A &&... args) { if (deferMessages_) { anyDeferredMessages_ = true; } else { - messages_.Say(range, args...).SetContext(context_.get()); + messages_.Say(range, std::forward(args)...).SetContext(context_.get()); } } - template void Say(const MessageFixedText &text, A... args) { - Say(p_, text, args...); + template void Say(const MessageFixedText &text, A &&... args) { + Say(p_, text, std::forward(args)...); } - template void Say(const MessageExpectedText &text, A... args) { - Say(p_, text, args...); + template + void Say(const MessageExpectedText &text, A &&... args) { + Say(p_, text, std::forward(args)...); } void Nonstandard(LanguageFeature lf, const MessageFixedText &msg) { diff --git a/flang/lib/parser/parse-tree.h b/flang/lib/parser/parse-tree.h index 12a1436c12a6..f8828a605eab 100644 --- a/flang/lib/parser/parse-tree.h +++ b/flang/lib/parser/parse-tree.h @@ -108,7 +108,7 @@ struct GenericExprWrapper; // forward definition, wraps Expr // Many other classes below simply wrap a std::tuple<> structure, which // is conventionally named "t". #define TUPLE_CLASS_BOILERPLATE(classname) \ - template)> \ + template \ classname(Ts &&... args) : t(std::move(args)...) {} \ using TupleTrait = std::true_type; \ BOILERPLATE(classname) diff --git a/flang/lib/parser/prescan.h b/flang/lib/parser/prescan.h index 444bd7fee69f..948fc3f08e2e 100644 --- a/flang/lib/parser/prescan.h +++ b/flang/lib/parser/prescan.h @@ -70,8 +70,8 @@ public: TokenSequence TokenizePreprocessorDirective(); Provenance GetCurrentProvenance() const { return GetProvenance(at_); } - template Message &Say(A... a) { - Message &m{messages_.Say(a...)}; + template Message &Say(A &&... a) { + Message &m{messages_.Say(std::forward(a)...)}; std::optional range{m.GetProvenanceRange(cooked_)}; CHECK(!range.has_value() || cooked_.IsValid(*range)); return m; diff --git a/flang/lib/semantics/assignment.cc b/flang/lib/semantics/assignment.cc index 603f93a452cc..0ff23afe1eb8 100644 --- a/flang/lib/semantics/assignment.cc +++ b/flang/lib/semantics/assignment.cc @@ -120,8 +120,8 @@ private: MaskExpr GetMask(const parser::LogicalExpr &, bool defaultValue = true) const; - template parser::Message *Say(A... args) { - return messages_.Say(args...); + template parser::Message *Say(A &&... args) { + return messages_.Say(std::forward(args)...); } SemanticsContext &context_; diff --git a/flang/lib/semantics/expression.h b/flang/lib/semantics/expression.h index 604981cb7a5d..ce01c7abad9a 100644 --- a/flang/lib/semantics/expression.h +++ b/flang/lib/semantics/expression.h @@ -80,14 +80,13 @@ public: return GetFoldingContext().messages(); } - template - parser::Message *Say(A &&... args) { - return GetContextualMessages().Say(std::move(args)...); + template parser::Message *Say(A &&... args) { + return GetContextualMessages().Say(std::forward(args)...); } - template + template parser::Message *SayAt(const T &parsed, A &&... args) { - return Say(parser::FindSourceLocation(parsed), std::move(args)...); + return Say(parser::FindSourceLocation(parsed), std::forward(args)...); } int GetDefaultKind(common::TypeCategory); diff --git a/flang/lib/semantics/resolve-names.cc b/flang/lib/semantics/resolve-names.cc index bcb22778e2c0..27d9e70a4bbd 100644 --- a/flang/lib/semantics/resolve-names.cc +++ b/flang/lib/semantics/resolve-names.cc @@ -172,12 +172,11 @@ public: } } - template - Message &Say(const parser::Name &name, A &&... args) { - return messageHandler_.Say(name.source, std::move(args)...); + template Message &Say(const parser::Name &name, A &&... args) { + return messageHandler_.Say(name.source, std::forward(args)...); } - template Message &Say(A &&... args) { - return messageHandler_.Say(std::move(args)...); + template Message &Say(A &&... args) { + return messageHandler_.Say(std::forward(args)...); } private: diff --git a/flang/lib/semantics/semantics.h b/flang/lib/semantics/semantics.h index e802b96f23ff..6fa38173e2e0 100644 --- a/flang/lib/semantics/semantics.h +++ b/flang/lib/semantics/semantics.h @@ -83,14 +83,13 @@ public: bool AnyFatalError() const; - template + template parser::Message &Say(const parser::CharBlock &at, A &&... args) { - return messages_.Say(at, std::move(args)...); + return messages_.Say(at, std::forward(args)...); } - template - parser::Message &Say(A &&... args) { + template parser::Message &Say(A &&... args) { CHECK(location_); - return messages_.Say(*location_, std::move(args)...); + return messages_.Say(*location_, std::forward(args)...); } parser::Message &Say(parser::Message &&msg) { return messages_.Say(std::move(msg));