forked from OSchip/llvm-project
Split -Wunused-variable warning.
With r190382, -Wunused-variable warns about unused const variables when appropriate. For codebases that use -Werror, this poses a problem as existing unused const variables need to be cleaned up first. To make the transistion easier, this patch splits -Wunused-variable by pulling out an additional -Wunused-const-variable (by default activated along with -Wunused-variable). llvm-svn: 190508
This commit is contained in:
parent
fa5ab1c856
commit
c531daefd9
|
@ -336,7 +336,9 @@ def UnusedLabel : DiagGroup<"unused-label">;
|
|||
def UnusedParameter : DiagGroup<"unused-parameter">;
|
||||
def UnusedResult : DiagGroup<"unused-result">;
|
||||
def UnusedValue : DiagGroup<"unused-value", [UnusedComparison, UnusedResult]>;
|
||||
def UnusedVariable : DiagGroup<"unused-variable">;
|
||||
def UnusedConstVariable : DiagGroup<"unused-const-variable">;
|
||||
def UnusedVariable : DiagGroup<"unused-variable",
|
||||
[UnusedConstVariable]>;
|
||||
def UsedButMarkedUnused : DiagGroup<"used-but-marked-unused">;
|
||||
def UserDefinedLiterals : DiagGroup<"user-defined-literals">;
|
||||
def ReadOnlySetterAttrs : DiagGroup<"readonly-setter-attrs">;
|
||||
|
|
|
@ -155,6 +155,8 @@ def warn_unused_parameter : Warning<"unused parameter %0">,
|
|||
InGroup<UnusedParameter>, DefaultIgnore;
|
||||
def warn_unused_variable : Warning<"unused variable %0">,
|
||||
InGroup<UnusedVariable>, DefaultIgnore;
|
||||
def warn_unused_const_variable : Warning<"unused variable %0">,
|
||||
InGroup<UnusedConstVariable>, DefaultIgnore;
|
||||
def warn_unused_exception_param : Warning<"unused exception parameter %0">,
|
||||
InGroup<UnusedExceptionParameter>, DefaultIgnore;
|
||||
def warn_decl_in_param_list : Warning<
|
||||
|
|
|
@ -758,6 +758,9 @@ void Sema::ActOnEndOfTranslationUnit() {
|
|||
if (DiagD->isReferenced()) {
|
||||
Diag(DiagD->getLocation(), diag::warn_unneeded_internal_decl)
|
||||
<< /*variable*/1 << DiagD->getDeclName();
|
||||
} else if (DiagD->getType().isConstQualified()) {
|
||||
Diag(DiagD->getLocation(), diag::warn_unused_const_variable)
|
||||
<< DiagD->getDeclName();
|
||||
} else {
|
||||
Diag(DiagD->getLocation(), diag::warn_unused_variable)
|
||||
<< DiagD->getDeclName();
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
// RUN: %clang_cc1 -fsyntax-only -Wunused-variable -Wno-unused-const-variable -verify %s
|
||||
|
||||
namespace {
|
||||
int i = 0; // expected-warning {{unused variable 'i'}}
|
||||
const int j = 0;;
|
||||
}
|
Loading…
Reference in New Issue