@@ -161,16 +161,21 @@ bool Message::SortBefore(const Message &that) const {
161161 location_, that.location_ );
162162}
163163
164- bool Message::IsFatal () const {
165- return severity () == Severity::Error || severity () == Severity::Todo;
164+ bool Message::IsFatal (bool warningsAreErrors) const {
165+ Severity sev{severity (warningsAreErrors)};
166+ return sev == Severity::Error || sev == Severity::Todo;
166167}
167168
168- Severity Message::severity () const {
169+ Severity Message::severity (bool warningsAreErrors ) const {
169170 return common::visit (
170171 common::visitors{
171172 [](const MessageExpectedText &) { return Severity::Error; },
172- [](const MessageFixedText &x) { return x.severity (); },
173- [](const MessageFormattedText &x) { return x.severity (); },
173+ [=](const MessageFixedText &x) {
174+ return x.severity (warningsAreErrors);
175+ },
176+ [=](const MessageFormattedText &x) {
177+ return x.severity (warningsAreErrors);
178+ },
174179 },
175180 text_);
176181}
@@ -295,15 +300,16 @@ static constexpr int MAX_CONTEXTS_EMITTED{2};
295300static constexpr bool OMIT_SHARED_CONTEXTS{true };
296301
297302void Message::Emit (llvm::raw_ostream &o, const AllCookedSources &allCooked,
298- bool echoSourceLine,
299- const common::LanguageFeatureControl *hintFlagPtr ) const {
303+ bool echoSourceLine, const common::LanguageFeatureControl *hintFlagPtr,
304+ bool warningsAreErrors ) const {
300305 std::optional<ProvenanceRange> provenanceRange{GetProvenanceRange (allCooked)};
301306 const AllSources &sources{allCooked.allSources ()};
302307 const std::string text{ToString ()};
308+ Severity sev{severity (warningsAreErrors)};
303309 const std::string hint{
304310 HintLanguageControlFlag (hintFlagPtr, languageFeature_, usageWarning_)};
305- sources.EmitMessage (o, provenanceRange, text + hint, Prefix (severity () ),
306- PrefixColor (severity () ), echoSourceLine);
311+ sources.EmitMessage (o, provenanceRange, text + hint, Prefix (sev ),
312+ PrefixColor (sev ), echoSourceLine);
307313 // Refers to whether the attachment in the loop below is a context, but can't
308314 // be declared inside the loop because the previous iteration's
309315 // attachment->attachmentIsContext_ indicates this.
@@ -453,7 +459,7 @@ void Messages::ResolveProvenances(const AllCookedSources &allCooked) {
453459
454460void Messages::Emit (llvm::raw_ostream &o, const AllCookedSources &allCooked,
455461 bool echoSourceLines, const common::LanguageFeatureControl *hintFlagPtr,
456- std::size_t maxErrorsToEmit) const {
462+ std::size_t maxErrorsToEmit, bool warningsAreErrors ) const {
457463 std::vector<const Message *> sorted;
458464 for (const auto &msg : messages_) {
459465 sorted.push_back (&msg);
@@ -467,9 +473,9 @@ void Messages::Emit(llvm::raw_ostream &o, const AllCookedSources &allCooked,
467473 // Don't emit two identical messages for the same location
468474 continue ;
469475 }
470- msg->Emit (o, allCooked, echoSourceLines, hintFlagPtr);
476+ msg->Emit (o, allCooked, echoSourceLines, hintFlagPtr, warningsAreErrors );
471477 lastMsg = msg;
472- if (msg->IsFatal ()) {
478+ if (msg->IsFatal (warningsAreErrors )) {
473479 ++errorsEmitted;
474480 }
475481 // If maxErrorsToEmit is 0, emit all errors, otherwise break after
@@ -491,9 +497,12 @@ void Messages::AttachTo(Message &msg, std::optional<Severity> severity) {
491497 messages_.clear ();
492498}
493499
494- bool Messages::AnyFatalError () const {
500+ bool Messages::AnyFatalError (bool warningsAreErrors) const {
501+ if (messages_.empty ()) {
502+ return false ;
503+ }
495504 for (const auto &msg : messages_) {
496- if (msg.IsFatal ()) {
505+ if (msg.IsFatal (warningsAreErrors )) {
497506 return true ;
498507 }
499508 }
0 commit comments