[cfe-commits] r166361 - in /cfe/trunk: lib/CodeGen/CGExpr.cpp lib/Sema/SemaExpr.cpp test/CodeGenCXX/const-init-cxx11.cpp test/CodeGenCXX/for-range.cpp test/CodeGenCXX/lambda-expressions.cpp test/SemaCXX/lambda-expressions.cpp

Argyrios Kyrtzidis kyrtzidis at apple.com
Fri Oct 26 17:08:05 PDT 2012


On Oct 26, 2012, at 4:43 PM, Richard Smith <richard at metafoo.co.uk> wrote:

> On Fri, Oct 26, 2012 at 1:54 PM, Argyrios Kyrtzidis <kyrtzidis at apple.com> wrote:
>> On Oct 26, 2012, at 1:35 PM, Richard Smith <richard at metafoo.co.uk> wrote:
>> 
>>> Argyrios: It looks like you added this warning in r129794. Can you
>>> comment on what it's intended to detect?
>> 
>> variables/functions with internal linkage that are not used from the codegen perspective.
>> This differs from -Wunused which will consider a 'use' even in an unevaluated context.
> 
> Why is that a useful thing to warn on?

Because it means you have unused code/data resulting from a bug (bad) or a refactoring (bad hygiene), etc.

> 
>> For example:
>> 
>> static void foo() { }
>> 
>> this gives:
>> warning: unused function 'foo' [-Wunused-function]
>> 
>> static void foo() { }
>> template <typename T>
>> void goo() {
>>  foo();
>> }
>> 
>> this gives:
>> warning: function 'foo' is not needed and will not be emitted [-Wunneeded-internal-declaration]
> 
> That code certainly looks bogus, but I don't think that's the right
> warning. We should warn either on the definition of 'goo' (because it
> has external linkage but uses an internal linkage function) or warn
> that 'goo' is unused and can't be used outside this TU.

Here's a more realistic example:

static int data1[100];
static int data2[300];

int data1_size() {
	return sizeof(data1);
};

int data2_size() {
	return sizeof(data2);
};

int *get_data1() {
	return data1;
}

int *get_data2() {
	return data1; // Oops, typo.
}


This gives:
warning: variable 'data2' is not needed and will not be emitted [-Wunneeded-internal-declaration]



More information about the cfe-commits mailing list