dgregor, I committed this as it was the lowest risk patch to fix the
regression. Let me know if you think we should change the side marking
the decls used instead.

On 25 December 2012 23:38, Rafael Espindola <[email protected]> wrote:
> Author: rafael
> Date: Tue Dec 25 22:38:44 2012
> New Revision: 171088
>
> URL: http://llvm.org/viewvc/llvm-project?rev=171088&view=rev
> Log:
> 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.
>
> Modified:
>     cfe/trunk/lib/Sema/Sema.cpp
>     cfe/trunk/test/SemaCXX/warn-func-not-needed.cpp
>
> Modified: cfe/trunk/lib/Sema/Sema.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.cpp?rev=171088&r1=171087&r2=171088&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/Sema.cpp (original)
> +++ cfe/trunk/lib/Sema/Sema.cpp Tue Dec 25 22:38:44 2012
> @@ -328,7 +328,11 @@
>
>  /// \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)) {
>
> Modified: cfe/trunk/test/SemaCXX/warn-func-not-needed.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-func-not-needed.cpp?rev=171088&r1=171087&r2=171088&view=diff
> ==============================================================================
> --- cfe/trunk/test/SemaCXX/warn-func-not-needed.cpp (original)
> +++ cfe/trunk/test/SemaCXX/warn-func-not-needed.cpp Tue Dec 25 22:38:44 2012
> @@ -15,3 +15,16 @@
>    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>();
> +  }
> +}
>
>
> _______________________________________________
> cfe-commits mailing list
> [email protected]
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to