Merge type of diagnostic and its substitutions. (#366)

This commit is contained in:
Richard Smith
2021-03-08 15:17:21 -08:00
committed by GitHub
parent f61b1b18ca
commit 62ae0e08cf
3 changed files with 44 additions and 59 deletions
+16 -20
View File
@@ -21,15 +21,14 @@ struct FakeDiagnostic {
// selection of the message.
static constexpr llvm::StringLiteral Message = "{0}";
struct Substitutions {
std::string message;
};
static auto Format(const Substitutions& substitutions) -> std::string {
std::string message;
auto Format() -> std::string {
// Work around a bug in Clang's unused const variable warning by marking it
// used here with a no-op.
static_cast<void>(ShortName);
return llvm::formatv(Message.data(), substitutions.message).str();
return llvm::formatv(Message.data(), message).str();
}
};
@@ -55,21 +54,18 @@ TEST(DiagTest, EmitWarnings) {
reported.push_back(diagnostic.message);
});
emitter.EmitWarningIf<FakeDiagnostic>(
[](FakeDiagnostic::Substitutions& diagnostic) {
diagnostic.message = "M1";
return true;
});
emitter.EmitWarningIf<FakeDiagnostic>(
[](FakeDiagnostic::Substitutions& diagnostic) {
diagnostic.message = "M2";
return false;
});
emitter.EmitWarningIf<FakeDiagnostic>(
[](FakeDiagnostic::Substitutions& diagnostic) {
diagnostic.message = "M3";
return true;
});
emitter.EmitWarningIf<FakeDiagnostic>([](FakeDiagnostic& diagnostic) {
diagnostic.message = "M1";
return true;
});
emitter.EmitWarningIf<FakeDiagnostic>([](FakeDiagnostic& diagnostic) {
diagnostic.message = "M2";
return false;
});
emitter.EmitWarningIf<FakeDiagnostic>([](FakeDiagnostic& diagnostic) {
diagnostic.message = "M3";
return true;
});
EXPECT_THAT(reported, ElementsAre("M1", "M3"));
}