[cfe-commits] r171458 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/SemaCXX/warn-unused-filescoped.cpp
Rafael Espindola
rafael.espindola at gmail.com
Wed Jan 2 20:29:21 PST 2013
Author: rafael
Date: Wed Jan 2 22:29:20 2013
New Revision: 171458
URL: http://llvm.org/viewvc/llvm-project?rev=171458&view=rev
Log:
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.
Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/SemaCXX/warn-unused-filescoped.cpp
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=171458&r1=171457&r2=171458&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Jan 2 22:29:20 2013
@@ -4537,8 +4537,6 @@
// member, set the visibility of this variable.
if (NewVD->getLinkage() == ExternalLinkage && !DC->isRecord())
AddPushedVisibilityAttribute(NewVD);
-
- MarkUnusedFileScopedDecl(NewVD);
return NewVD;
}
@@ -7348,6 +7346,9 @@
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>() ||
Modified: cfe/trunk/test/SemaCXX/warn-unused-filescoped.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-unused-filescoped.cpp?rev=171458&r1=171457&r2=171458&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-unused-filescoped.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-unused-filescoped.cpp Wed Jan 2 22:29:20 2013
@@ -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 @@
void bar();
};
}
+
+namespace pr14776 {
+ namespace {
+ struct X {};
+ }
+ X a = X(); // expected-warning {{unused variable 'a'}}
+ auto b = X(); // expected-warning {{unused variable 'b'}}
+}
More information about the cfe-commits
mailing list