diff options
Diffstat (limited to 'lib/Sema/Sema.cpp')
-rw-r--r-- | lib/Sema/Sema.cpp | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp index e444f3c357..4b82069a62 100644 --- a/lib/Sema/Sema.cpp +++ b/lib/Sema/Sema.cpp @@ -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)) { |