diff options
author | Anna Zaks <ganna@apple.com> | 2011-07-28 20:52:06 +0000 |
---|---|---|
committer | Anna Zaks <ganna@apple.com> | 2011-07-28 20:52:06 +0000 |
commit | d5612a235fdd5df145c485c6ac489fcfbf7120d3 (patch) | |
tree | 899ab60596a1efb3aa5f87f928b63cc625116a23 /lib/Sema/SemaDecl.cpp | |
parent | 7efa0e03828dd13e53f5310fc80471604f298d48 (diff) |
Add a fixit for removal of unused label.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@136389 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaDecl.cpp')
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 321ab780d4..4988323f41 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -1086,12 +1086,28 @@ static bool ShouldDiagnoseUnusedDecl(const NamedDecl *D) { return true; } +static void GenerateFixForUnusedDecl(const NamedDecl *D, ASTContext &Ctx, + FixItHint &Hint) { + if (isa<LabelDecl>(D)) { + SourceLocation AfterColon = Lexer::findLocationAfterToken(D->getLocEnd(), + tok::colon, Ctx.getSourceManager(), Ctx.getLangOptions(), true); + if (AfterColon.isInvalid()) + return; + Hint = FixItHint::CreateRemoval(CharSourceRange:: + getCharRange(D->getLocStart(), AfterColon)); + } + return; +} + /// DiagnoseUnusedDecl - Emit warnings about declarations that are not used /// unless they are marked attr(unused). void Sema::DiagnoseUnusedDecl(const NamedDecl *D) { + FixItHint Hint; if (!ShouldDiagnoseUnusedDecl(D)) return; + GenerateFixForUnusedDecl(D, Context, Hint); + unsigned DiagID; if (isa<VarDecl>(D) && cast<VarDecl>(D)->isExceptionVariable()) DiagID = diag::warn_unused_exception_param; @@ -1100,7 +1116,7 @@ void Sema::DiagnoseUnusedDecl(const NamedDecl *D) { else DiagID = diag::warn_unused_variable; - Diag(D->getLocation(), DiagID) << D->getDeclName(); + Diag(D->getLocation(), DiagID) << D->getDeclName() << Hint; } static void CheckPoppedLabel(LabelDecl *L, Sema &S) { |