r178294 - Warn about more than the first unused variable when -Werror is set.

Matt Beaumont-Gay matthewbg at google.com
Thu Mar 28 14:46:45 PDT 2013


Author: matthewbg
Date: Thu Mar 28 16:46:45 2013
New Revision: 178294

URL: http://llvm.org/viewvc/llvm-project?rev=178294&view=rev
Log:
Warn about more than the first unused variable when -Werror is set.

To do this, thread DiagnosticErrorTrap's hasUnrecoverableErrorOccurred through
to Scope.

Added:
    cfe/trunk/test/Sema/warn-unused-variables-werror.c
Modified:
    cfe/trunk/include/clang/Sema/Scope.h
    cfe/trunk/lib/Sema/SemaDecl.cpp

Modified: cfe/trunk/include/clang/Sema/Scope.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Scope.h?rev=178294&r1=178293&r2=178294&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Scope.h (original)
+++ cfe/trunk/include/clang/Sema/Scope.h Thu Mar 28 16:46:45 2013
@@ -240,7 +240,11 @@ public:
   void setEntity(void *E) { Entity = E; }
 
   bool hasErrorOccurred() const { return ErrorTrap.hasErrorOccurred(); }
-                           
+
+  bool hasUnrecoverableErrorOccurred() const {
+    return ErrorTrap.hasUnrecoverableErrorOccurred();
+  }
+
   /// isClassScope - Return true if this scope is a class/struct/union scope.
   bool isClassScope() const {
     return (getFlags() & Scope::ClassScope);

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=178294&r1=178293&r2=178294&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Mar 28 16:46:45 2013
@@ -1389,7 +1389,7 @@ void Sema::ActOnPopScope(SourceLocation
     if (!D->getDeclName()) continue;
 
     // Diagnose unused variables in this scope.
-    if (!S->hasErrorOccurred())
+    if (!S->hasUnrecoverableErrorOccurred())
       DiagnoseUnusedDecl(D);
     
     // If this was a forward reference to a label, verify it was defined.

Added: cfe/trunk/test/Sema/warn-unused-variables-werror.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-unused-variables-werror.c?rev=178294&view=auto
==============================================================================
--- cfe/trunk/test/Sema/warn-unused-variables-werror.c (added)
+++ cfe/trunk/test/Sema/warn-unused-variables-werror.c Thu Mar 28 16:46:45 2013
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -fsyntax-only -Wunused-variable -Werror -verify %s
+
+void f() {
+  int i;  // expected-error{{unused}}
+  int j;  // expected-error{{unused}}
+}





More information about the cfe-commits mailing list