FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Debian > Debian GCC

 
 
LinkBack Thread Tools
 
Old 01-05-2012, 10:35 PM
Jonathan Nieder
 
Default Bug#625357: gcc -Wunused-but-set-variable warning is confusing

reassign 625357 src:gcc-snapshot 20111210-1
affects 625357 + gcc-4.6
affects 625357 + gcc-4.7
quit

Jonathan Nieder wrote:
> Steve McIntyre wrote:

>> error = add_md5_entry(UNKNOWN, md5, file_name);
>> return 0;
>> }
>>
>> To explain a bit more: the warning reported by gcc (unhelpfully)
>> points at the declaration/initialisation of "error", which led me to
>> (incorrectly) think that it was complaining about set-but-unused for
>> the initialisation. With minor tweaks, I can see that it's complaining
>> about the return value from add_md5_entry() being ignored but doesn't
>> *say* that. :-(
>
> Ah, I see and I think I agree.
[...]
> Something like
>
> test.c:3:6: warning: unused variable ‘x’ [-Wunused-but-set-variable]
>
> would be clearer.

Here's a rough patch. Will send upstream after testing, but thoughts
welcome already. Sensible?
From: Jonathan Nieder <jrnieder@gmail.com>
Date: Thu, 5 Jan 2012 17:13:29 -0600
Subject: gcc: make -Wunused-but-set-variable message less confusing

gcc:
* c-decl.c (pop_scope, finish_function): Say "unused variable
‘x’ [-Wunused-but-set-variable]" instead of "variable ‘x’ set
but not used [-Wunused-but-set-variable]" to put the emphasis
on the "unused" part.
* cp/decl.c (pop_scope, finish_function): Likewise.

gcc/testsuite:
* c-c++-common/Wunused-var-1.c (f1, f2, f5, f8, f14, f17, f18, f20):
Substitute "unused" for "set but not used" in expected warnings.
* c-c++-common/Wunused-var-3.c (f1): Likewise.
* c-c++-common/Wunused-var-4.c (f3): Likewise.
* c-c++-common/Wunused-var-7.c (bar): Likewise.
* c-c++-common/Wunused-var-9.c (f6): Likewise.
* c-c++-common/Wunused-var-12.c (bar): Likewise.
* g++.dg/template/sfinae16.C (main): Likewise.
* g++.dg/warn/Wunused-7.C (func): Likewise.
* g++.dg/warn/Wunused-var-4.C (f1, f2): Likewise.
* g++.dg/warn/Wunused-var-5.C (f1, f2, f5, f8, f14, f17, f18, f20):
Likewise.
* g++.dg/warn/Wunused-var-7.C (f1): Likewise.
* g++.dg/warn/Wunused-var-10.C (f3): Likewise.
* objc.dg/set-not-used-1.m (main): Likewise.
* obj-c++.dg/set-not-used-1.mm (main): Likewise.

* gcc.dg/Wunused-parm-1.c (f3): Substitute "unused parameter" for "set
but not used" in expected warning.
* g++.dg/warn/Wunused-parm-1.C (f4): Likewise.
* g++.dg/warn/Wunused-parm-2.C (f4): Likewise.

* gcc.dg/Wunused-var-1.c (f2): Substitute "unused variable" for "set but
not used" in expected warning.
---
gcc/c-decl.c | 4 ++--
gcc/cp/decl.c | 4 ++--
gcc/testsuite/c-c++-common/Wunused-var-1.c | 18 +++++++++---------
gcc/testsuite/c-c++-common/Wunused-var-12.c | 2 +-
gcc/testsuite/c-c++-common/Wunused-var-3.c | 4 ++--
gcc/testsuite/c-c++-common/Wunused-var-4.c | 4 ++--
gcc/testsuite/c-c++-common/Wunused-var-7.c | 2 +-
gcc/testsuite/c-c++-common/Wunused-var-9.c | 2 +-
gcc/testsuite/g++.dg/template/sfinae16.C | 2 +-
gcc/testsuite/g++.dg/warn/Wunused-7.C | 2 +-
gcc/testsuite/g++.dg/warn/Wunused-parm-1.C | 2 +-
gcc/testsuite/g++.dg/warn/Wunused-parm-2.C | 2 +-
gcc/testsuite/g++.dg/warn/Wunused-var-10.C | 2 +-
gcc/testsuite/g++.dg/warn/Wunused-var-4.C | 10 +++++-----
gcc/testsuite/g++.dg/warn/Wunused-var-5.C | 18 +++++++++---------
gcc/testsuite/g++.dg/warn/Wunused-var-7.C | 4 ++--
gcc/testsuite/gcc.dg/Wunused-parm-1.c | 2 +-
gcc/testsuite/gcc.dg/Wunused-var-1.c | 2 +-
gcc/testsuite/obj-c++.dg/set-not-used-1.mm | 6 +++---
gcc/testsuite/objc.dg/set-not-used-1.m | 6 +++---
20 files changed, 49 insertions(+), 49 deletions(-)

diff --git a/gcc/c-decl.c b/gcc/c-decl.c
index 96e9c7d1..bde2668f 100644
--- a/gcc/c-decl.c
+++ b/gcc/c-decl.c
@@ -1176,7 +1176,7 @@ pop_scope (void)
else if (DECL_CONTEXT (p) == current_function_decl)
warning_at (DECL_SOURCE_LOCATION (p),
OPT_Wunused_but_set_variable,
- "variable %qD set but not used", p);
+ "unused variable %qD", p);
}

if (b->inner_comp)
@@ -8396,7 +8396,7 @@ finish_function (void)
&& !TREE_NO_WARNING (decl))
warning_at (DECL_SOURCE_LOCATION (decl),
OPT_Wunused_but_set_parameter,
- "parameter %qD set but not used", decl);
+ "unused parameter %qD", decl);
}

/* Complain about locally defined typedefs that are not used in this
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 7daac5fe..e832880a 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -634,7 +634,7 @@ poplevel (int keep, int reverse, int functionbody)
|| !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (decl))))
{
warning (OPT_Wunused_but_set_variable,
- "variable %q+D set but not used", decl);
+ "unused variable %q+D", decl);
unused_but_set_errorcount = errorcount;
}
}
@@ -13527,7 +13527,7 @@ finish_function (int flags)
&& (!CLASS_TYPE_P (TREE_TYPE (decl))
|| !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (decl))))
warning (OPT_Wunused_but_set_parameter,
- "parameter %q+D set but not used", decl);
+ "unused parameter %q+D", decl);
unused_but_set_errorcount = errorcount;
}

diff --git a/gcc/testsuite/c-c++-common/Wunused-var-1.c b/gcc/testsuite/c-c++-common/Wunused-var-1.c
index ef8f6d45..201ae343 100644
--- a/gcc/testsuite/c-c++-common/Wunused-var-1.c
+++ b/gcc/testsuite/c-c++-common/Wunused-var-1.c
@@ -4,7 +4,7 @@
void
f1 (void)
{
- int a; /* { dg-warning "set but not used" } */
+ int a; /* { dg-warning "unused" } */
int b;
int c;
c = 1;
@@ -14,9 +14,9 @@ f1 (void)
void
f2 (int x)
{
- int a; /* { dg-warning "set but not used" } */
+ int a; /* { dg-warning "unused" } */
int b;
- int c; /* { dg-warning "set but not used" } */
+ int c; /* { dg-warning "unused" } */
c = (a = x, b = x);
}

@@ -38,7 +38,7 @@ f4 (int x)
void
f5 (int x)
{
- int a[2]; /* { dg-warning "set but not used" } */
+ int a[2]; /* { dg-warning "unused" } */
int b;
int *c, d[2];
c = d;
@@ -70,7 +70,7 @@ struct S { int i; };
void
f8 (void)
{
- struct S s; /* { dg-warning "set but not used" } */
+ struct S s; /* { dg-warning "unused" } */
s.i = 6;
}

@@ -118,7 +118,7 @@ f13 (void (*x) (void))
void
f14 (void (*x) (void))
{
- void (*a) (void); /* { dg-warning "set but not used" } */
+ void (*a) (void); /* { dg-warning "unused" } */
a = x;
}

@@ -145,7 +145,7 @@ f16 (void)
void
f17 (int x)
{
- long a; /* { dg-warning "set but not used" } */
+ long a; /* { dg-warning "unused" } */
int b;
a = b = x;
}
@@ -153,7 +153,7 @@ f17 (int x)
void
f18 (int x)
{
- int a; /* { dg-warning "set but not used" } */
+ int a; /* { dg-warning "unused" } */
int b;
a = (char) (b = x);
}
@@ -173,7 +173,7 @@ f20 (int x)
{
static int a[] = { 3, 4, 5, 6 };
static int b[] = { 4, 5, 6, 7 };
- static int c[] = { 5, 6, 7, 8 }; /* { dg-warning "set but not used" } */
+ static int c[] = { 5, 6, 7, 8 }; /* { dg-warning "unused" } */
c[1] = 1;
return x ? a : b;
}
diff --git a/gcc/testsuite/c-c++-common/Wunused-var-12.c b/gcc/testsuite/c-c++-common/Wunused-var-12.c
index 94e56d8a..a77bc650 100644
--- a/gcc/testsuite/c-c++-common/Wunused-var-12.c
+++ b/gcc/testsuite/c-c++-common/Wunused-var-12.c
@@ -20,7 +20,7 @@ void
bar (void)
{
vec a;
- vec b; /* { dg-warning "set but not used" } */
+ vec b; /* { dg-warning "unused" } */
a = c;
b = a;
}
diff --git a/gcc/testsuite/c-c++-common/Wunused-var-3.c b/gcc/testsuite/c-c++-common/Wunused-var-3.c
index 9b1fce77..79aa47bf 100644
--- a/gcc/testsuite/c-c++-common/Wunused-var-3.c
+++ b/gcc/testsuite/c-c++-common/Wunused-var-3.c
@@ -4,8 +4,8 @@
void
f1 (void)
{
- _Complex int a; /* { dg-warning "set but not used" } */
- _Complex double b; /* { dg-warning "set but not used" } */
+ _Complex int a; /* { dg-warning "unused" } */
+ _Complex double b; /* { dg-warning "unused" } */
__real__ a = 1;
__imag__ a = 2;
__real__ b = 3.0;
diff --git a/gcc/testsuite/c-c++-common/Wunused-var-4.c b/gcc/testsuite/c-c++-common/Wunused-var-4.c
index d60c476a..5169e7f1 100644
--- a/gcc/testsuite/c-c++-common/Wunused-var-4.c
+++ b/gcc/testsuite/c-c++-common/Wunused-var-4.c
@@ -22,8 +22,8 @@ f2 (void)
void
f3 (void)
{
- struct S { int i; } a; /* { dg-warning "set but not used" } */
- int b[1]; /* { dg-warning "set but not used" } */
+ struct S { int i; } a; /* { dg-warning "unused" } */
+ int b[1]; /* { dg-warning "unused" } */
a.i = 1;
b[0] = 1;
}
diff --git a/gcc/testsuite/c-c++-common/Wunused-var-7.c b/gcc/testsuite/c-c++-common/Wunused-var-7.c
index 74196436..1ce0c509 100644
--- a/gcc/testsuite/c-c++-common/Wunused-var-7.c
+++ b/gcc/testsuite/c-c++-common/Wunused-var-7.c
@@ -26,7 +26,7 @@ bar (void)
{
int a;
int b;
- int c; /* { dg-warning "set but not used" } */
+ int c; /* { dg-warning "unused" } */
a = 1;
b = 2;
c = 3;
diff --git a/gcc/testsuite/c-c++-common/Wunused-var-9.c b/gcc/testsuite/c-c++-common/Wunused-var-9.c
index b2cdc451..58390ca9 100644
--- a/gcc/testsuite/c-c++-common/Wunused-var-9.c
+++ b/gcc/testsuite/c-c++-common/Wunused-var-9.c
@@ -26,7 +26,7 @@ f5 (int x)
void
f6 (int x)
{
- int a; /* { dg-warning "set but not used" } */
+ int a; /* { dg-warning "unused" } */
a = x;
}

diff --git a/gcc/testsuite/g++.dg/template/sfinae16.C b/gcc/testsuite/g++.dg/template/sfinae16.C
index 28a06d28..c5dc1ef3 100644
--- a/gcc/testsuite/g++.dg/template/sfinae16.C
+++ b/gcc/testsuite/g++.dg/template/sfinae16.C
@@ -29,6 +29,6 @@ template<typename Rep>
int main()
{
duration<int> d0;
- duration<int> d1 = d0; // { dg-warning "set but not used" }
+ duration<int> d1 = d0; // { dg-warning "unused" }
}

diff --git a/gcc/testsuite/g++.dg/warn/Wunused-7.C b/gcc/testsuite/g++.dg/warn/Wunused-7.C
index 6f5c23e9..d4414ad9 100644
--- a/gcc/testsuite/g++.dg/warn/Wunused-7.C
+++ b/gcc/testsuite/g++.dg/warn/Wunused-7.C
@@ -6,7 +6,7 @@ void func()
struct mybitfields {
unsigned int s_field:8;
};
- struct mybitfields s; // { dg-warning "set but not used" }
+ struct mybitfields s; // { dg-warning "unused" }
s.s_field = 255;
};

diff --git a/gcc/testsuite/g++.dg/warn/Wunused-parm-1.C b/gcc/testsuite/g++.dg/warn/Wunused-parm-1.C
index 08bfaa66..28bee57f 100644
--- a/gcc/testsuite/g++.dg/warn/Wunused-parm-1.C
+++ b/gcc/testsuite/g++.dg/warn/Wunused-parm-1.C
@@ -25,7 +25,7 @@ f3 (int a) // { dg-warning "unused parameter" }
}

int
-f4 (int a) // { dg-warning "set but not used" }
+f4 (int a) // { dg-warning "unused parameter" }
{
a = 1;
return 0;
diff --git a/gcc/testsuite/g++.dg/warn/Wunused-parm-2.C b/gcc/testsuite/g++.dg/warn/Wunused-parm-2.C
index d4276c0a..fb660b7f 100644
--- a/gcc/testsuite/g++.dg/warn/Wunused-parm-2.C
+++ b/gcc/testsuite/g++.dg/warn/Wunused-parm-2.C
@@ -29,7 +29,7 @@ f3 (int a) // { dg-warning "unused parameter" }

template <int N>
int
-f4 (int a) // { dg-warning "set but not used" }
+f4 (int a) // { dg-warning "unused parameter" }
{
a = 1;
return 0;
diff --git a/gcc/testsuite/g++.dg/warn/Wunused-var-10.C b/gcc/testsuite/g++.dg/warn/Wunused-var-10.C
index ffdb8932..6ffd35d3 100644
--- a/gcc/testsuite/g++.dg/warn/Wunused-var-10.C
+++ b/gcc/testsuite/g++.dg/warn/Wunused-var-10.C
@@ -29,7 +29,7 @@ f2 ()
void
f3 ()
{
- S s; // { dg-warning "set but not used" }
+ S s; // { dg-warning "unused" }
s.c = 6;
}

diff --git a/gcc/testsuite/g++.dg/warn/Wunused-var-4.C b/gcc/testsuite/g++.dg/warn/Wunused-var-4.C
index 11ed7afe..6e7ee1b9 100644
--- a/gcc/testsuite/g++.dg/warn/Wunused-var-4.C
+++ b/gcc/testsuite/g++.dg/warn/Wunused-var-4.C
@@ -16,9 +16,9 @@ f1 (void)
c = 3;
d = 4;
s.e = 5;
- __typeof (c) e; // { dg-warning "set but not used" }
- __decltype (d) f; // { dg-warning "set but not used" }
- __decltype (s.e) g; // { dg-warning "set but not used" }
+ __typeof (c) e; // { dg-warning "unused" }
+ __decltype (d) f; // { dg-warning "unused" }
+ __decltype (s.e) g; // { dg-warning "unused" }
e = 1;
f = 1;
g = 1;
@@ -36,8 +36,8 @@ int f2 (void)
b = 2;
c = 3;
d = 4;
- __typeof (c) e; // { dg-warning "set but not used" }
- __decltype (d) f; // { dg-warning "set but not used" }
+ __typeof (c) e; // { dg-warning "unused" }
+ __decltype (d) f; // { dg-warning "unused" }
e = 1;
f = 1;
return sizeof (a) + __alignof__ (b);
diff --git a/gcc/testsuite/g++.dg/warn/Wunused-var-5.C b/gcc/testsuite/g++.dg/warn/Wunused-var-5.C
index 7fcaa955..96fc613e 100644
--- a/gcc/testsuite/g++.dg/warn/Wunused-var-5.C
+++ b/gcc/testsuite/g++.dg/warn/Wunused-var-5.C
@@ -5,7 +5,7 @@ template <int N>
void
f1 (void)
{
- int a; // { dg-warning "set but not used" }
+ int a; // { dg-warning "unused" }
int b;
int c;
c = 1;
@@ -16,9 +16,9 @@ template <int N>
void
f2 (int x)
{
- int a; // { dg-warning "set but not used" }
+ int a; // { dg-warning "unused" }
int b;
- int c; // { dg-warning "set but not used" }
+ int c; // { dg-warning "unused" }
c = (a = x, b = x);
}

@@ -43,7 +43,7 @@ template <int N>
void
f5 (int x)
{
- int a[2]; // { dg-warning "set but not used" }
+ int a[2]; // { dg-warning "unused" }
int b;
int *c, d[2];
c = d;
@@ -78,7 +78,7 @@ template <int N>
void
f8 (void)
{
- struct S s; // { dg-warning "set but not used" }
+ struct S s; // { dg-warning "unused" }
s.i = 6;
}

@@ -132,7 +132,7 @@ template <int N>
void
f14 (void (*x) (void))
{
- void (*a) (void); // { dg-warning "set but not used" }
+ void (*a) (void); // { dg-warning "unused" }
a = x;
}

@@ -162,7 +162,7 @@ template <int N>
void
f17 (int x)
{
- long a; // { dg-warning "set but not used" }
+ long a; // { dg-warning "unused" }
int b;
a = b = x;
}
@@ -171,7 +171,7 @@ template <int N>
void
f18 (int x)
{
- int a; // { dg-warning "set but not used" }
+ int a; // { dg-warning "unused" }
int b;
a = (char) (b = x);
}
@@ -193,7 +193,7 @@ f20 (int x)
{
static int a[] = { 3, 4, 5, 6 };
static int b[] = { 4, 5, 6, 7 };
- static int c[] = { 5, 6, 7, 8 }; // { dg-warning "set but not used" }
+ static int c[] = { 5, 6, 7, 8 }; // { dg-warning "unused" }
c[1] = 1;
return x ? a : b;
}
diff --git a/gcc/testsuite/g++.dg/warn/Wunused-var-7.C b/gcc/testsuite/g++.dg/warn/Wunused-var-7.C
index cf1b605c..3479fdf2 100644
--- a/gcc/testsuite/g++.dg/warn/Wunused-var-7.C
+++ b/gcc/testsuite/g++.dg/warn/Wunused-var-7.C
@@ -5,8 +5,8 @@ template <int N>
void
f1 (void)
{
- _Complex int a; // { dg-warning "set but not used" }
- _Complex double b; // { dg-warning "set but not used" }
+ _Complex int a; // { dg-warning "unused" }
+ _Complex double b; // { dg-warning "unused" }
__real__ a = 1;
__imag__ a = 2;
__real__ b = 3.0;
diff --git a/gcc/testsuite/gcc.dg/Wunused-parm-1.c b/gcc/testsuite/gcc.dg/Wunused-parm-1.c
index bddbd83a..0fdf5faf 100644
--- a/gcc/testsuite/gcc.dg/Wunused-parm-1.c
+++ b/gcc/testsuite/gcc.dg/Wunused-parm-1.c
@@ -20,7 +20,7 @@ f2 (int x, int y)

int
f3 (int a, /* { dg-warning "unused parameter" } */
- int b, /* { dg-warning "set but not used" } */
+ int b, /* { dg-warning "unused parameter" } */
int c)
{
b = 1;
diff --git a/gcc/testsuite/gcc.dg/Wunused-var-1.c b/gcc/testsuite/gcc.dg/Wunused-var-1.c
index d60dd70e..c326a3c6 100644
--- a/gcc/testsuite/gcc.dg/Wunused-var-1.c
+++ b/gcc/testsuite/gcc.dg/Wunused-var-1.c
@@ -16,7 +16,7 @@ f1 (void)
void
f2 (void)
{
- int a; /* { dg-warning "set but not used" } */
+ int a; /* { dg-warning "unused variable" } */
void foo (void)
{
a = 2;
diff --git a/gcc/testsuite/obj-c++.dg/set-not-used-1.mm b/gcc/testsuite/obj-c++.dg/set-not-used-1.mm
index 21ce962e..5b4c57fe 100644
--- a/gcc/testsuite/obj-c++.dg/set-not-used-1.mm
+++ b/gcc/testsuite/obj-c++.dg/set-not-used-1.mm
@@ -21,9 +21,9 @@

int main (void)
{
- obj *a; /* { dg-bogus "set but not used" } */
- obj *b; /* { dg-bogus "set but not used" } */
- obj *c; /* { dg-warning "set but not used" } */
+ obj *a; /* { dg-bogus "unused" } */
+ obj *b; /* { dg-bogus "unused" } */
+ obj *c; /* { dg-warning "unused" } */

a = [obj new];
b = [obj new];
diff --git a/gcc/testsuite/objc.dg/set-not-used-1.m b/gcc/testsuite/objc.dg/set-not-used-1.m
index 21ce962e..5b4c57fe 100644
--- a/gcc/testsuite/objc.dg/set-not-used-1.m
+++ b/gcc/testsuite/objc.dg/set-not-used-1.m
@@ -21,9 +21,9 @@

int main (void)
{
- obj *a; /* { dg-bogus "set but not used" } */
- obj *b; /* { dg-bogus "set but not used" } */
- obj *c; /* { dg-warning "set but not used" } */
+ obj *a; /* { dg-bogus "unused" } */
+ obj *b; /* { dg-bogus "unused" } */
+ obj *c; /* { dg-warning "unused" } */

a = [obj new];
b = [obj new];
--
1.7.8.2
 

Thread Tools




All times are GMT. The time now is 05:35 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org