]> granicus.if.org Git - clang/commitdiff
Basic/Diagnostics: Apparently, #pragma ... diagnostic is intended to override
authorDaniel Dunbar <daniel@zuster.org>
Tue, 4 Oct 2011 21:17:24 +0000 (21:17 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Tue, 4 Oct 2011 21:17:24 +0000 (21:17 +0000)
the command line options (at least according to GCC's documentation). GCC 4.2
didn't appear to actually do this, but it seems like that has been fixed in
later release, so we will follow the docs.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@141119 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Basic/Diagnostic.cpp
test/Frontend/warning-mapping-5.c [new file with mode: 0644]

index cfe617e2b3c148ad65d7ad97280f87054267da4e..e5f390196d80e067b76ad2c4292bbe4af0cb7c9c 100644 (file)
@@ -175,6 +175,13 @@ void DiagnosticsEngine::setDiagnosticMapping(diag::kind Diag, diag::Mapping Map,
   DiagnosticMappingInfo MappingInfo = DiagnosticMappingInfo::Make(
     Map, /*IsUser=*/true, isPragma);
 
+  // If this is a pragma mapping, then set the diagnostic mapping flags so that
+  // we override command line options.
+  if (isPragma) {
+    MappingInfo.setNoWarningAsError(true);
+    MappingInfo.setNoErrorAsFatal(true);
+  }
+
   // Common case; setting all the diagnostics of a group in one place.
   if (Loc.isInvalid() || Loc == LastStateChangePos) {
     GetCurDiagState()->setMappingInfo(Diag, MappingInfo);
diff --git a/test/Frontend/warning-mapping-5.c b/test/Frontend/warning-mapping-5.c
new file mode 100644 (file)
index 0000000..27d53dc
--- /dev/null
@@ -0,0 +1,9 @@
+// Check that #pragma diagnostic warning overrides -Werror. This matches GCC's
+// original documentation, but not its earlier implementations.
+// 
+// RUN: %clang_cc1 -verify -Werror %s
+
+#pragma clang diagnostic warning "-Wsign-compare"
+int f0(int x, unsigned y) {
+  return x < y; // expected-warning {{comparison of integers}}
+}