mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-27 20:16:05 +00:00
If there were errors, disable 'unused' warnings since they will mostly be noise.
Fixes rdar://8736362. llvm-svn: 124577
This commit is contained in:
parent
b85cd7c312
commit
77fd99f8ae
@ -388,25 +388,29 @@ void Sema::ActOnEndOfTranslationUnit() {
|
||||
Consumer.CompleteTentativeDefinition(VD);
|
||||
|
||||
}
|
||||
|
||||
// Output warning for unused file scoped decls.
|
||||
for (llvm::SmallVectorImpl<const DeclaratorDecl*>::iterator
|
||||
I = UnusedFileScopedDecls.begin(),
|
||||
E = UnusedFileScopedDecls.end(); I != E; ++I) {
|
||||
if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(*I)) {
|
||||
const FunctionDecl *DiagD;
|
||||
if (!FD->hasBody(DiagD))
|
||||
DiagD = FD;
|
||||
Diag(DiagD->getLocation(),
|
||||
isa<CXXMethodDecl>(DiagD) ? diag::warn_unused_member_function
|
||||
: diag::warn_unused_function)
|
||||
<< DiagD->getDeclName();
|
||||
} else {
|
||||
const VarDecl *DiagD = cast<VarDecl>(*I)->getDefinition();
|
||||
if (!DiagD)
|
||||
DiagD = cast<VarDecl>(*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<const DeclaratorDecl*>::iterator
|
||||
I = UnusedFileScopedDecls.begin(),
|
||||
E = UnusedFileScopedDecls.end(); I != E; ++I) {
|
||||
if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(*I)) {
|
||||
const FunctionDecl *DiagD;
|
||||
if (!FD->hasBody(DiagD))
|
||||
DiagD = FD;
|
||||
Diag(DiagD->getLocation(),
|
||||
isa<CXXMethodDecl>(DiagD) ? diag::warn_unused_member_function
|
||||
: diag::warn_unused_function)
|
||||
<< DiagD->getDeclName();
|
||||
} else {
|
||||
const VarDecl *DiagD = cast<VarDecl>(*I)->getDefinition();
|
||||
if (!DiagD)
|
||||
DiagD = cast<VarDecl>(*I);
|
||||
Diag(DiagD->getLocation(), diag::warn_unused_variable)
|
||||
<< DiagD->getDeclName();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
8
clang/test/SemaCXX/unused-with-error.cpp
Normal file
8
clang/test/SemaCXX/unused-with-error.cpp
Normal file
@ -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}}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user