]> granicus.if.org Git - clang/commitdiff
Warn on unused auto variables.
authorRafael Espindola <rafael.espindola@gmail.com>
Thu, 3 Jan 2013 04:29:20 +0000 (04:29 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Thu, 3 Jan 2013 04:29:20 +0000 (04:29 +0000)
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

lib/Sema/SemaDecl.cpp
test/SemaCXX/warn-unused-filescoped.cpp

index 624f40582b28b9f5c6b9946819bf24889b4ecf15..61791b2aa58a76d5fbfefe562c5f82316d85b550 100644 (file)
@@ -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>() ||
index 4cb38d997b133f9cefacfb0cd66725a3d3464b9d..e12668bf2a466739420a8bc6611c0c8de5e4e7d9 100644 (file)
@@ -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'}}
+}