From: Argyrios Kyrtzidis Date: Mon, 31 Jan 2011 07:04:37 +0000 (+0000) Subject: If there were errors, disable 'unused' warnings since they will mostly be noise. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=43f0a7c8e06e55092b43d4dd46fe09a4d57298e9;p=clang If there were errors, disable 'unused' warnings since they will mostly be noise. Fixes rdar://8736362. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@124577 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp index 44bb71e57b..1fd12d3b7a 100644 --- a/lib/Sema/Sema.cpp +++ b/lib/Sema/Sema.cpp @@ -388,25 +388,29 @@ void Sema::ActOnEndOfTranslationUnit() { Consumer.CompleteTentativeDefinition(VD); } - - // Output warning for unused file scoped decls. - for (llvm::SmallVectorImpl::iterator - I = UnusedFileScopedDecls.begin(), - E = UnusedFileScopedDecls.end(); I != E; ++I) { - if (const FunctionDecl *FD = dyn_cast(*I)) { - const FunctionDecl *DiagD; - if (!FD->hasBody(DiagD)) - DiagD = FD; - Diag(DiagD->getLocation(), - isa(DiagD) ? diag::warn_unused_member_function - : diag::warn_unused_function) - << DiagD->getDeclName(); - } else { - const VarDecl *DiagD = cast(*I)->getDefinition(); - if (!DiagD) - DiagD = cast(*I); - Diag(DiagD->getLocation(), diag::warn_unused_variable) - << DiagD->getDeclName(); + + // If there were errors, disable 'unused' warnings since they will mostly be + // noise. + if (!Diags.hasErrorOccurred()) { + // Output warning for unused file scoped decls. + for (llvm::SmallVectorImpl::iterator + I = UnusedFileScopedDecls.begin(), + E = UnusedFileScopedDecls.end(); I != E; ++I) { + if (const FunctionDecl *FD = dyn_cast(*I)) { + const FunctionDecl *DiagD; + if (!FD->hasBody(DiagD)) + DiagD = FD; + Diag(DiagD->getLocation(), + isa(DiagD) ? diag::warn_unused_member_function + : diag::warn_unused_function) + << DiagD->getDeclName(); + } else { + const VarDecl *DiagD = cast(*I)->getDefinition(); + if (!DiagD) + DiagD = cast(*I); + Diag(DiagD->getLocation(), diag::warn_unused_variable) + << DiagD->getDeclName(); + } } } diff --git a/test/SemaCXX/unused-with-error.cpp b/test/SemaCXX/unused-with-error.cpp new file mode 100644 index 0000000000..5660007c3b --- /dev/null +++ b/test/SemaCXX/unused-with-error.cpp @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 -fsyntax-only -Wunused -verify %s + +// Make sure 'unused' warnings are disabled when errors occurred. +static void foo(int *X) { // expected-note {{candidate}} +} +void bar(const int *Y) { + foo(Y); // expected-error {{no matching function for call}} +}