]> granicus.if.org Git - clang/commitdiff
fix PR5933: don't warn about unused variables if a function has other errors in it.
authorChris Lattner <sabre@nondot.org>
Mon, 1 Mar 2010 21:06:03 +0000 (21:06 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 1 Mar 2010 21:06:03 +0000 (21:06 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@97498 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
test/Sema/warn-unused-variables.c

index be4a591f29af7d1207e4a615e7aa0041c660c2f8..4842da2a7b544423628347af0329946d7731835e 100644 (file)
@@ -553,7 +553,8 @@ void Sema::ActOnPopScope(SourceLocation Loc, Scope *S) {
     if (!D->getDeclName()) continue;
 
     // Diagnose unused variables in this scope.
-    if (ShouldDiagnoseUnusedDecl(D))
+    if (ShouldDiagnoseUnusedDecl(D) &&
+        NumErrorsAtStartOfFunction == getDiagnostics().getNumErrors())
       Diag(D->getLocation(), diag::warn_unused_variable) << D->getDeclName();
     
     // Remove this name from our lexical scope.
index 36615061fe6fd9e68da5171525a3ae2415b25d61..4d1cde7067e514150b3a58e0e939f55382c82795 100644 (file)
@@ -17,3 +17,9 @@ void f1(void) {
        (void)sizeof(i);
        return;
 }
+
+// PR5933
+int f2() {
+  int X = 4;  // Shouldn't have a bogus 'unused variable X' warning.
+  return Y + X; // expected-error {{use of undeclared identifier 'Y'}}
+}