diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2013-01-03 04:29:20 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2013-01-03 04:29:20 +0000 |
commit | 6769ccb6853871c085c8366ab5e993841ad56d00 (patch) | |
tree | 145e2dea940867ad682d6553e517726852aa0f41 | |
parent | da844b3483669c64d02082ff2a9e68d46bd00c1f (diff) |
Warn on unused auto variables.
To do so we have to wait until we know that the type of a variable has been
deduced. Sema::FinalizeDeclaration is the first callback that is used for
decl with or without initializers.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171458 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 5 | ||||
-rw-r--r-- | test/SemaCXX/warn-unused-filescoped.cpp | 10 |
2 files changed, 12 insertions, 3 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 624f40582b..61791b2aa5 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -4537,8 +4537,6 @@ Sema::ActOnVariableDeclarator(Scope *S, Declarator &D, DeclContext *DC, // member, set the visibility of this variable. if (NewVD->getLinkage() == ExternalLinkage && !DC->isRecord()) AddPushedVisibilityAttribute(NewVD); - - MarkUnusedFileScopedDecl(NewVD); return NewVD; } @@ -7348,6 +7346,9 @@ Sema::FinalizeDeclaration(Decl *ThisDecl) { if (!VD) return; + if (VD->isFileVarDecl()) + MarkUnusedFileScopedDecl(VD); + // Now we have parsed the initializer and can update the table of magic // tag values. if (!VD->hasAttr<TypeTagForDatatypeAttr>() || diff --git a/test/SemaCXX/warn-unused-filescoped.cpp b/test/SemaCXX/warn-unused-filescoped.cpp index 4cb38d997b..e12668bf2a 100644 --- a/test/SemaCXX/warn-unused-filescoped.cpp +++ b/test/SemaCXX/warn-unused-filescoped.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify -Wunused -Wunused-member-function -std=c++98 %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wunused -Wunused-member-function -Wno-c++11-extensions -std=c++98 %s // RUN: %clang_cc1 -fsyntax-only -verify -Wunused -Wunused-member-function -std=c++11 %s static void f1(); // expected-warning{{unused}} @@ -132,3 +132,11 @@ namespace test6 { void bar(); }; } + +namespace pr14776 { + namespace { + struct X {}; + } + X a = X(); // expected-warning {{unused variable 'a'}} + auto b = X(); // expected-warning {{unused variable 'b'}} +} |