On 24 December 2012 17:12, Rafael Ávila de Espíndola
<[email protected]> wrote:
> This fixes pr14691, which I think is a regression from r168519.
>
> Let me know if you think we should mark all previous decls instead, but as
> far as I can tell we only ever look at the current or at the first decl.

Now that I think of it, it is probably best to just change
ShouldRemoveFromUnused. The attached patch does that.


> ---
>  lib/Sema/SemaExpr.cpp                 |  5 +++++
>  test/SemaCXX/warn-func-not-needed.cpp | 17 +++++++++++++++++
>  2 files changed, 22 insertions(+)
>  create mode 100644 test/SemaCXX/warn-func-not-needed.cpp
>
> diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
> index 191a26d..a5dd1dc 100644
> --- a/lib/Sema/SemaExpr.cpp
> +++ b/lib/Sema/SemaExpr.cpp
> @@ -10497,6 +10497,11 @@ void Sema::MarkFunctionReferenced(SourceLocation 
> Loc, FunctionDecl *Func) {
>    }
>
>    Func->setUsed(true);
> +
> +  // We use the first declaration to keep track of unused global declarations
> +  // (see UnusedFileScopedDecls), so mark it used too.
> +  FunctionDecl *First = Func->getFirstDeclaration();
> +  First->setUsed(true);
>  }
>
>  static void
> diff --git a/test/SemaCXX/warn-func-not-needed.cpp 
> b/test/SemaCXX/warn-func-not-needed.cpp
> new file mode 100644
> index 0000000..437a428
> --- /dev/null
> +++ b/test/SemaCXX/warn-func-not-needed.cpp
> @@ -0,0 +1,17 @@
> +// RUN: %clang_cc1 -fsyntax-only -verify -Wall %s
> +
> +namespace test1 {
> +  static void f() {} // expected-warning {{is not needed and will not be 
> emitted}}
> +  static void f();
> +  template <typename T>
> +  void foo() {
> +    f();
> +  }
> +}
> +
> +namespace test2 {
> +  static void f() {}
> +  static void f();
> +  static void g() { f(); }
> +  void h() { g(); }
> +}
> --
> 1.7.11.7
>

Attachment: t.patch
Description: Binary data

_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to