Fix a regression from the previous commit.

Template instantiation can set the canonical decl to used after subsequent
decls have been chained, so we have to check that too.

llvm-svn: 171088
This commit is contained in:
Rafael Espindola 2012-12-26 04:38:44 +00:00
parent a2594dd5f0
commit 1779760cb4
2 changed files with 18 additions and 1 deletions

View File

@ -328,7 +328,11 @@ CastKind Sema::ScalarTypeToBooleanCastKind(QualType ScalarTy) {
/// \brief Used to prune the decls of Sema's UnusedFileScopedDecls vector.
static bool ShouldRemoveFromUnused(Sema *SemaRef, const DeclaratorDecl *D) {
if (D->getMostRecentDecl()->isUsed())
// Template instantiation can happen at the end of the translation unit
// and it sets the canonical (first) decl to used. Normal uses set the last
// decl at the time to used and subsequent decl inherit the flag. The net
// result is that we need to check both ends of the decl chain.
if (D->isUsed() || D->getMostRecentDecl()->isUsed())
return true;
if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {

View File

@ -15,3 +15,16 @@ namespace test2 {
static void g() { f(); }
void h() { g(); }
}
namespace test3 {
static void f();
template<typename T>
static void g() {
f();
}
static void f() {
}
void h() {
g<int>();
}
}