bool adjustDiagFromHeader(Diag &D, const clang::Diagnostic &Info,
const LangOptions &LangOpts) {
// We only report diagnostics with at least error severity from headers.
- if (D.Severity < DiagnosticsEngine::Level::Error)
+ // Use default severity to avoid noise with -Werror.
+ if (!Info.getDiags()->getDiagnosticIDs()->isDefaultMappingAsError(
+ Info.getID()))
return false;
const SourceManager &SM = Info.getSourceManager();
if (Info.getLocation().isInvalid()) {
// Handle diagnostics coming from command-line arguments. The source manager
// is *not* available at this point, so we cannot use it.
- if (DiagLevel < DiagnosticsEngine::Level::Error) {
+ if (!Info.getDiags()->getDiagnosticIDs()->isDefaultMappingAsError(
+ Info.getID())) {
IgnoreDiagnostics::log(DiagLevel, Info);
return; // non-errors add too much noise, do not show them.
}
WithNote(Diag(Header.range(), "error occurred here")))));
}
+TEST(DiagsInHeaders, OnlyDefaultErrorOrFatal) {
+ Annotations Main(R"cpp(
+ #include [["a.h"]] // get unused "foo" warning when building preamble.
+ )cpp");
+ Annotations Header(R"cpp(
+ namespace { void foo() {} }
+ void func() {foo();} ;)cpp");
+ TestTU TU = TestTU::withCode(Main.code());
+ TU.AdditionalFiles = {{"a.h", std::string(Header.code())}};
+ // promote warnings to errors.
+ TU.ExtraArgs = {"-Werror", "-Wunused"};
+ EXPECT_THAT(TU.build().getDiagnostics(), IsEmpty());
+}
+
TEST(DiagsInHeaders, FromNonWrittenSources) {
Annotations Main(R"cpp(
#include [["a.h"]]