[cfe-commits] [PATCH] When marking a function used, also mark the first redeclaration.
Douglas Gregor
dgregor at apple.com
Tue Dec 25 14:22:26 PST 2012
Sent from my iPhone
On Dec 25, 2012, at 2:48 AM, Rafael Espíndola <rafael.espindola at gmail.com> wrote:
> On 24 December 2012 17:12, Rafael Ávila de Espíndola
> <rafael.espindola at gmail.com> 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.
Do we propagate the used bit to redeclarations? If not, we should. I like this version a lot better.
>
>> ---
>> 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
> <t.patch>
More information about the cfe-commits
mailing list