diff options
author | Jakub Jelinek <jakub@redhat.com> | 2010-05-06 08:52:30 +0200 |
---|---|---|
committer | Dodji Seketeli <dodji@gcc.gnu.org> | 2010-05-06 08:52:30 +0200 |
commit | 03a904b5a683713f848ef028aef63e0cfd16c4eb (patch) | |
tree | 98529df86d4f96b7809a5e235901996abf394d3f /gcc/testsuite | |
parent | 7d8930a046c5d5c80f990eef73c278b4c124b6f4 (diff) | |
download | gcc-03a904b5a683713f848ef028aef63e0cfd16c4eb.zip gcc-03a904b5a683713f848ef028aef63e0cfd16c4eb.tar.gz gcc-03a904b5a683713f848ef028aef63e0cfd16c4eb.tar.bz2 |
C++ support for -Wunused-but-set-variable
gcc/cp/ChangeLog:
PR 18624
* cp-tree.h (mark_exp_read, mark_rvalue_use, mark_lvalue_use,
mark_type_use): Declare ...
* expr.c (mark_exp_read, mark_rvalue_use, mark_lvalue_use,
mark_type_use): ... new fns.
* typeck.c (cxx_sizeof_expr, cxx_alignof_expr): Call mark_type_use.
(perform_integral_promotions): Call mark_rvalue_use.
(cp_build_unary_op): Call mark_lvalue_use.
(decay_conversion): Update comment. Call mark_lvalue.
* decl.c (unused_but_set_errorcount): New variable.
(poplevel): Issue -Wunused-but-set-variable diagnostics.
(duplicate_decls): Merge DECL_READ_P flags.
(start_cleanup_fn): Set DECL_READ_P flag.
(finish_function): Issue -Wunused-but-set-parameter diagnostics.
* tree.c (rvalue): Call mark_rvalue_use.
* pt.c (convert_nontype_argument): Likewise.
* semantics.c (finish_typeof, finish_decltype_type): Call
mark_type_use.
(finish_asm_stmt): Call mark_lvalue_use.
(finish_expr_stmt): Call mark_exp_read.
* call.c (convert_like_real) <ck_identity, ck_user>: Call
mark_rvalue_use.
(build_x_va_arg): Call mark_lvalue_use.
(build_over_call): Call mark_type_use.
* init.c (build_new, build_delete): Call mark_value_use.
* rtti.c (build_typeid): Call mark_lvalue_use or mark_type_use.
(build_dynamic_cast_1): call mark_lvalue_use or mark_rvalue_use.
gcc/testsuite/ChangeLog:
PR 18624
* g++.dg/warn/Wunused-7.C: Add dg-warning.
* g++.dg/template/sfinae16.C: Likewise.
* gcc.dg/Wunused-var-1.c: Moved to...
* c-c++-common/Wunused-var-1.c: ...here. New test.
* gcc.dg/Wunused-var-2.c: Moved to...
* c-c++-common/Wunused-var-2.c: ...here. New test.
* gcc.dg/Wunused-var-3.c: Moved to...
* c-c++-common/Wunused-var-3.c: ...here. New test.
* gcc.dg/Wunused-var-4.c: Moved to...
* gcc.dg/Wunused-var-1.c: ... here.
* gcc.dg/Wunused-var-5.c: Moved to...
* c-c++-common/Wunused-var-4.c: ...here. New test.
* gcc.dg/Wunused-var-7.c: Moved to...
* c-c++-common/Wunused-var-5.c: ...here. New test.
* gcc.dg/Wunused-var-6.c: Moved to...
* gcc.dg/Wunused-var-2.c: ... here.
* c-c++-common/Wunused-var-1.c: New test.
* c-c++-common/Wunused-var-2.c: New test.
* c-c++-common/Wunused-var-3.c: New test.
* c-c++-common/Wunused-var-4.c: New test.
* c-c++-common/Wunused-var-5.c: New test.
* g++.dg/warn/Wunused-var-1.C: New test.
* g++.dg/warn/Wunused-var-2.C: New test.
* g++.dg/warn/Wunused-var-3.C: New test.
* g++.dg/warn/Wunused-var-4.C: New test.
* g++.dg/warn/Wunused-var-5.C: New test.
* g++.dg/warn/Wunused-var-6.C: New test.
* g++.dg/warn/Wunused-var-7.C: New test.
* g++.dg/warn/Wunused-var-8.C: New test.
* g++.dg/warn/Wunused-parm-1.C: New test.
* g++.dg/warn/Wunused-parm-2.C: New test.
* g++.dg/warn/Wunused-parm-3.C: New test.
Co-Authored-By: Dodji Seketeli <dodji@redhat.com>
From-SVN: r159096
Diffstat (limited to 'gcc/testsuite')
23 files changed, 1068 insertions, 228 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 686fc38..36eea3d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,40 @@ +2010-04-22 Jakub Jelinek <jakub@redhat.com> + Dodji Seketeli <dodji@redhat.com> + + PR c/18624 + * g++.dg/warn/Wunused-7.C: Add dg-warning. + * g++.dg/template/sfinae16.C: Likewise. + * gcc.dg/Wunused-var-1.c: Moved to... + * c-c++-common/Wunused-var-1.c: ...here. New test. + * gcc.dg/Wunused-var-2.c: Moved to... + * c-c++-common/Wunused-var-2.c: ...here. New test. + * gcc.dg/Wunused-var-3.c: Moved to... + * c-c++-common/Wunused-var-3.c: ...here. New test. + * gcc.dg/Wunused-var-4.c: Moved to... + * gcc.dg/Wunused-var-1.c: ... here. + * gcc.dg/Wunused-var-5.c: Moved to... + * c-c++-common/Wunused-var-4.c: ...here. New test. + * gcc.dg/Wunused-var-7.c: Moved to... + * c-c++-common/Wunused-var-5.c: ...here. New test. + * gcc.dg/Wunused-var-6.c: Moved to... + * gcc.dg/Wunused-var-2.c: ... here. + * c-c++-common/Wunused-var-1.c: New test. + * c-c++-common/Wunused-var-2.c: New test. + * c-c++-common/Wunused-var-3.c: New test. + * c-c++-common/Wunused-var-4.c: New test. + * c-c++-common/Wunused-var-5.c: New test. + * g++.dg/warn/Wunused-var-1.C: New test. + * g++.dg/warn/Wunused-var-2.C: New test. + * g++.dg/warn/Wunused-var-3.C: New test. + * g++.dg/warn/Wunused-var-4.C: New test. + * g++.dg/warn/Wunused-var-5.C: New test. + * g++.dg/warn/Wunused-var-6.C: New test. + * g++.dg/warn/Wunused-var-7.C: New test. + * g++.dg/warn/Wunused-var-8.C: New test. + * g++.dg/warn/Wunused-parm-1.C: New test. + * g++.dg/warn/Wunused-parm-2.C: New test. + * g++.dg/warn/Wunused-parm-3.C: New test. + 2010-05-06 Tobias Burnus <burnus@net-b.de> PR fortran/43985 diff --git a/gcc/testsuite/c-c++-common/Wunused-var-1.c b/gcc/testsuite/c-c++-common/Wunused-var-1.c new file mode 100644 index 0000000..ef8f6d4 --- /dev/null +++ b/gcc/testsuite/c-c++-common/Wunused-var-1.c @@ -0,0 +1,179 @@ +/* { dg-do compile } */ +/* { dg-options "-Wunused" } */ + +void +f1 (void) +{ + int a; /* { dg-warning "set but not used" } */ + int b; + int c; + c = 1; + a = b = c; +} + +void +f2 (int x) +{ + int a; /* { dg-warning "set but not used" } */ + int b; + int c; /* { dg-warning "set but not used" } */ + c = (a = x, b = x); +} + +int +f3 (int x) +{ + int a; + return a = x; +} + +int +f4 (int x) +{ + int a; + a = x; + return a; +} + +void +f5 (int x) +{ + int a[2]; /* { dg-warning "set but not used" } */ + int b; + int *c, d[2]; + c = d; + b = x; + a[b] = 1; + c[b] = 1; +} + +int +f6 (int x) +{ + int a[2]; + int b; + b = x; + a[b] = 1; + return a[b]; +} + +void +f7 (int x, int *p) +{ + int *a[2]; + a[x] = p; + a[x][x] = x; +} + +struct S { int i; }; + +void +f8 (void) +{ + struct S s; /* { dg-warning "set but not used" } */ + s.i = 6; +} + +int +f9 (void) +{ + struct S s; + s.i = 6; + return s.i; +} + +struct S +f10 (void) +{ + struct S s; + s.i = 6; + return s; +} + +extern int foo11 (int *); + +void +f11 (void) +{ + int a[2]; + foo11 (a); +} + +void +f12 (void) +{ + int a; + a = 1; + a; /* { dg-warning "no effect" } */ +} + +void +f13 (void (*x) (void)) +{ + void (*a) (void); + a = x; + a (); +} + +void +f14 (void (*x) (void)) +{ + void (*a) (void); /* { dg-warning "set but not used" } */ + a = x; +} + +extern void foo15 (int *); + +void +f15 (void) +{ + int a[10]; + int *b = a + 2; + foo15 (b); +} + +extern void foo16 (int **); + +void +f16 (void) +{ + int a[10]; + int *b[] = { a, a + 2 }; + foo16 (b); +} + +void +f17 (int x) +{ + long a; /* { dg-warning "set but not used" } */ + int b; + a = b = x; +} + +void +f18 (int x) +{ + int a; /* { dg-warning "set but not used" } */ + int b; + a = (char) (b = x); +} + +int +f19 (int x, int y, int z) +{ + int a; + int b; + a = x; + b = y; + return z ? a : b; +} + +int * +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" } */ + c[1] = 1; + return x ? a : b; +} diff --git a/gcc/testsuite/c-c++-common/Wunused-var-2.c b/gcc/testsuite/c-c++-common/Wunused-var-2.c new file mode 100644 index 0000000..2818259 --- /dev/null +++ b/gcc/testsuite/c-c++-common/Wunused-var-2.c @@ -0,0 +1,20 @@ +/* { dg-do compile } */ +/* { dg-options "-Wunused" } */ + +int +f1 (void) +{ + int c = ({ + int a; + a = 1; + a; }); + return c; +} + +void +f2 (void) +{ + int f; + f = 0; + __asm__ __volatile__ ("" : "+r" (f)); +} diff --git a/gcc/testsuite/gcc.dg/Wunused-var-3.c b/gcc/testsuite/c-c++-common/Wunused-var-3.c index 9b1fce7..9b1fce7 100644 --- a/gcc/testsuite/gcc.dg/Wunused-var-3.c +++ b/gcc/testsuite/c-c++-common/Wunused-var-3.c diff --git a/gcc/testsuite/gcc.dg/Wunused-var-7.c b/gcc/testsuite/c-c++-common/Wunused-var-4.c index e82e708..d60c476 100644 --- a/gcc/testsuite/gcc.dg/Wunused-var-7.c +++ b/gcc/testsuite/c-c++-common/Wunused-var-4.c @@ -14,9 +14,9 @@ f2 (void) struct S { int i; } a; int b[1]; a.i = 1; - a.i; /* { dg-warning "with no effect" } */ + a.i; /* { dg-warning "no effect" } */ b[0] = 1; - b[0]; /* { dg-warning "with no effect" } */ + b[0]; /* { dg-warning "no effect" } */ } void diff --git a/gcc/testsuite/gcc.dg/Wunused-var-5.c b/gcc/testsuite/c-c++-common/Wunused-var-5.c index 747f58d..747f58d 100644 --- a/gcc/testsuite/gcc.dg/Wunused-var-5.c +++ b/gcc/testsuite/c-c++-common/Wunused-var-5.c diff --git a/gcc/testsuite/g++.dg/template/sfinae16.C b/gcc/testsuite/g++.dg/template/sfinae16.C index 5ea564c..28a06d2 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; + duration<int> d1 = d0; // { dg-warning "set but not used" } } diff --git a/gcc/testsuite/g++.dg/warn/Wunused-7.C b/gcc/testsuite/g++.dg/warn/Wunused-7.C index 4281bc8..6f5c23e9 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; + struct mybitfields s; // { dg-warning "set but not used" } 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 new file mode 100644 index 0000000..08bfaa6 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-parm-1.C @@ -0,0 +1,58 @@ +// { dg-do compile } +// { dg-options "-Wunused -W" } + +long +f1 (unsigned long long x) +{ + unsigned long long a = 1; + const union { unsigned long long l; unsigned int p[2]; } b = { x }; + const union { unsigned long long l; unsigned int p[2]; } c = { a }; + return b.p[0] + c.p[0]; +} + +int +f2 (int x, int y) +{ + int a = 1; + int b[] = { 1, 2, x, a, 3, 4 }; + return b[y]; +} + +int +f3 (int a) // { dg-warning "unused parameter" } +{ + return 0; +} + +int +f4 (int a) // { dg-warning "set but not used" } +{ + a = 1; + return 0; +} + +int +f5 (int a) +{ + a = 1; + return a; +} + +int +f6 (int &a) +{ + return a; +} + +void +f7 (int &a) +{ + a = 1; +} + +struct S +{ + S (int i) : j(i) {} + S (long i) : j(i + 1) {} + int j; +}; diff --git a/gcc/testsuite/g++.dg/warn/Wunused-parm-2.C b/gcc/testsuite/g++.dg/warn/Wunused-parm-2.C new file mode 100644 index 0000000..d4276c0 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-parm-2.C @@ -0,0 +1,54 @@ +// { dg-do compile } +// { dg-options "-Wunused -W" } + +template <int N> +long +f1 (unsigned long long x) +{ + unsigned long long a = 1; + const union { unsigned long long l; unsigned int p[2]; } b = { x }; + const union { unsigned long long l; unsigned int p[2]; } c = { a }; + return b.p[0] + c.p[0]; +} + +template <int N> +int +f2 (int x, int y) +{ + int a = 1; + int b[] = { 1, 2, x, a, 3, 4 }; + return b[y]; +} + +template <int N> +int +f3 (int a) // { dg-warning "unused parameter" } +{ + return 0; +} + +template <int N> +int +f4 (int a) // { dg-warning "set but not used" } +{ + a = 1; + return 0; +} + +template <int N> +int +f5 (int a) +{ + a = 1; + return a; +} + +void +test () +{ + (void) f1<0> (0); + (void) f2<0> (0, 0); + (void) f3<0> (0); + (void) f4<0> (0); + (void) f5<0> (0); +} diff --git a/gcc/testsuite/g++.dg/warn/Wunused-parm-3.C b/gcc/testsuite/g++.dg/warn/Wunused-parm-3.C new file mode 100644 index 0000000..4d293f3 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-parm-3.C @@ -0,0 +1,69 @@ +// { dg-do compile } +// { dg-options "-Wunused -W" } + +#include <stdarg.h> + +struct A +{ + long a; + A () : a (0) { } + A (long x) : a (x) { } + operator long () const { return a; } + long operator- (const A& x) const { return a - x.a; } +}; + +long +fn1 (A a) +{ + return a - A (0); +} + +struct B +{ + bool operator() (const int x, const int y) const throw() { return x < y; } +}; + +template <typename T> +bool +fn2 (int x, int y, T z) +{ + return z (x, y); +} + +bool +fn3 (void) +{ + return fn2 (1, 2, B ()); +} + +int +fn4 (va_list ap) +{ + return va_arg (ap, int); +} + +template <typename T> +T +fn5 (va_list ap) +{ + return va_arg (ap, T); +} + +int +fn6 (va_list ap) +{ + return fn5 <int> (ap); +} + +template <typename T> +int +fn7 (T ap) +{ + return va_arg (ap, int); +} + +int +fn8 (va_list ap) +{ + return fn7 (ap); +} diff --git a/gcc/testsuite/g++.dg/warn/Wunused-var-1.C b/gcc/testsuite/g++.dg/warn/Wunused-var-1.C new file mode 100644 index 0000000..89c110b --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-var-1.C @@ -0,0 +1,8 @@ +// { dg-options "-Wunused" } +template <int> struct X { static const int s = 2; }; +template <typename T> int f() { const int v = 2; return X<v+1>::s; } +template <typename T> int g() { const int v = 2; return X<v>::s; } +template <typename T> int h() { const int v = 2; return X<1 ? v : 0>::s; } +template int f<int>(); +template int g<int>(); +template int h<int>(); diff --git a/gcc/testsuite/g++.dg/warn/Wunused-var-2.C b/gcc/testsuite/g++.dg/warn/Wunused-var-2.C new file mode 100644 index 0000000..0b21ef1 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-var-2.C @@ -0,0 +1,104 @@ +// { dg-options "-Wunused -W" } + +extern void foo (); + +void +f1 () +{ + try + { + foo (); + } + catch (int i) + { + } + catch (double d) + { + } +} + +void +f2 (int x) +{ + int a = 0; + x++; + ++a; +} + +struct A +{ + bool foo () const { return true; } +}; + +int +f3 () +{ + A a; + bool b = a.foo (); + return b; +} + +struct B +{ + int i; + B (int j); +}; + +void +f4 () +{ + B b (6); +} + +struct C +{ + int i; + C (int j) : i (j) {} +}; + +void +f5 () +{ + C c (6); +} + +struct D +{ + int i; + D (int j) : i (j) {} + ~D (); +}; + +void +f6 () +{ + D d (6); +} + +int *f7 (int s) +{ + return new int[s]; +} + +template <typename T> +T *f8 (int s) +{ + return new T[s]; +} + +template int *f8<int> (int); + +void +f9 (char *p) +{ + delete p; +} + +template <typename T> +void +f10 (T *p) +{ + delete p; +} + +template void f10<char> (char *); diff --git a/gcc/testsuite/g++.dg/warn/Wunused-var-3.C b/gcc/testsuite/g++.dg/warn/Wunused-var-3.C new file mode 100644 index 0000000..cd8931d --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-var-3.C @@ -0,0 +1,110 @@ +// { dg-options "-Wunused -W" } + +#include <typeinfo> +#include <stdarg.h> + +void +f1 (int a, ...) +{ + va_list ap; + va_start (ap, a); + va_end (ap); +} + +int +f2 (int a, ...) +{ + va_list ap; + va_start (ap, a); + int i = va_arg (ap, int); + va_end (ap); + return i; +} + +struct A { int a; A (); virtual ~A (); }; +struct B : virtual A { int b; }; + +struct B * +f3 (struct A *a) +{ + return dynamic_cast <B *> (a); +} + +struct A * +f4 (struct B *a) +{ + return static_cast <A *> (a); +} + +struct A * +f5 (struct B *a) +{ + return reinterpret_cast <A *> (a); +} + +struct A * +f6 (const struct A *a) +{ + return const_cast <A *> (a); +} + +int +f7 (long a) +{ + return (int) a; +} + +int +f8 (long a) +{ + return int (a); +} + +struct C +{ + operator unsigned int() { return 42; } +}; + +unsigned int +f9 () +{ + C u; + return u; +} + +struct D +{ + operator int & (); + operator const int & () const; +}; + +void foo (int &); +void foo (const int &); + +void +f10 () +{ + const D x = D (); + foo (x); +} + +int +f11 (int a) +{ + return typeid (a) == typeid (int); +} + +struct E +{ + int e () {return 0;} +}; + +template <typename T> +int +f12 (E a) +{ + __decltype (a.e()) i; + return i; +} + +template <> int f12<int> (E); diff --git a/gcc/testsuite/g++.dg/warn/Wunused-var-4.C b/gcc/testsuite/g++.dg/warn/Wunused-var-4.C new file mode 100644 index 0000000..11ed7af --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-var-4.C @@ -0,0 +1,50 @@ +/* { dg-do compile } */ +/* { dg-options "-Wunused" } */ + +struct S { int e; }; + +int +f1 (void) +{ + int a; + int b; + int c; + int d; + S s; + a = 1; + b = 2; + 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" } + e = 1; + f = 1; + g = 1; + return sizeof (a) + __alignof__ (b); +} + +template <int N> +int f2 (void) +{ + int a; + int b; + int c; + int d; + a = 1; + b = 2; + c = 3; + d = 4; + __typeof (c) e; // { dg-warning "set but not used" } + __decltype (d) f; // { dg-warning "set but not used" } + e = 1; + f = 1; + return sizeof (a) + __alignof__ (b); +} + +void +test (void) +{ + (void) f2<0> (); +} diff --git a/gcc/testsuite/g++.dg/warn/Wunused-var-5.C b/gcc/testsuite/g++.dg/warn/Wunused-var-5.C new file mode 100644 index 0000000..7fcaa95 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-var-5.C @@ -0,0 +1,227 @@ +// { dg-do compile } +// { dg-options "-Wunused" } + +template <int N> +void +f1 (void) +{ + int a; // { dg-warning "set but not used" } + int b; + int c; + c = 1; + a = b = c; +} + +template <int N> +void +f2 (int x) +{ + int a; // { dg-warning "set but not used" } + int b; + int c; // { dg-warning "set but not used" } + c = (a = x, b = x); +} + +template <int N> +int +f3 (int x) +{ + int a; + return a = x; +} + +template <int N> +int +f4 (int x) +{ + int a; + a = x; + return a; +} + +template <int N> +void +f5 (int x) +{ + int a[2]; // { dg-warning "set but not used" } + int b; + int *c, d[2]; + c = d; + b = x; + a[b] = 1; + c[b] = 1; +} + +template <int N> +int +f6 (int x) +{ + int a[2]; + int b; + b = x; + a[b] = 1; + return a[b]; +} + +template <int N> +void +f7 (int x, int *p) +{ + int *a[2]; + a[x] = p; + a[x][x] = x; +} + +struct S { int i; }; + +template <int N> +void +f8 (void) +{ + struct S s; // { dg-warning "set but not used" } + s.i = 6; +} + +template <int N> +int +f9 (void) +{ + struct S s; + s.i = 6; + return s.i; +} + +template <int N> +struct S +f10 (void) +{ + struct S s; + s.i = 6; + return s; +} + +extern int foo11 (int *); + +template <int N> +void +f11 (void) +{ + int a[2]; + foo11 (a); +} + +template <int N> +void +f12 (void) +{ + int a; + a = 1; + a; // { dg-warning "statement has no effect" } +} + +template <int N> +void +f13 (void (*x) (void)) +{ + void (*a) (void); + a = x; + a (); +} + +template <int N> +void +f14 (void (*x) (void)) +{ + void (*a) (void); // { dg-warning "set but not used" } + a = x; +} + +extern void foo15 (int *); + +template <int N> +void +f15 (void) +{ + int a[10]; + int *b = a + 2; + foo15 (b); +} + +extern void foo16 (int **); + +template <int N> +void +f16 (void) +{ + int a[10]; + int *b[] = { a, a + 2 }; + foo16 (b); +} + +template <int N> +void +f17 (int x) +{ + long a; // { dg-warning "set but not used" } + int b; + a = b = x; +} + +template <int N> +void +f18 (int x) +{ + int a; // { dg-warning "set but not used" } + int b; + a = (char) (b = x); +} + +template <int N> +int +f19 (int x, int y, int z) +{ + int a; + int b; + a = x; + b = y; + return z ? a : b; +} + +template <int N> +int * +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" } + c[1] = 1; + return x ? a : b; +} + +S s; + +void +test () +{ + int i = 0; + f1<0> (); + f2<0> (0); + (void) f3<0> (0); + (void) f4<0> (0); + f5<0> (0); + (void) f6<0> (0); + f7<0> (0, &i); + f8<0> (); + (void) f9<0> (); + s = f10<0> (); + f11<0> (); + f12<0> (); + f13<0> (f1<0>); + f14<0> (f1<0>); + f15<0> (); + f16<0> (); + f17<0> (0); + f18<0> (0); + (void) f19<0> (0, 0, 0); + (void) f20<0> (0); +} diff --git a/gcc/testsuite/g++.dg/warn/Wunused-var-6.C b/gcc/testsuite/g++.dg/warn/Wunused-var-6.C new file mode 100644 index 0000000..0fb8e5c --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-var-6.C @@ -0,0 +1,29 @@ +// { dg-do compile } +// { dg-options "-Wunused" } + +template <int N> +int +f1 (void) +{ + int c = ({ + int a; + a = 1; + a; }); + return c; +} + +template <int N> +void +f2 (void) +{ + int f; + f = 0; + __asm__ __volatile__ ("" : "+r" (f)); +} + +void +test () +{ + (void) f1<0> (); + f2<0> (); +} diff --git a/gcc/testsuite/g++.dg/warn/Wunused-var-7.C b/gcc/testsuite/g++.dg/warn/Wunused-var-7.C new file mode 100644 index 0000000..cf1b605 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-var-7.C @@ -0,0 +1,48 @@ +// { dg-do compile } +// { dg-options "-Wunused" } + +template <int N> +void +f1 (void) +{ + _Complex int a; // { dg-warning "set but not used" } + _Complex double b; // { dg-warning "set but not used" } + __real__ a = 1; + __imag__ a = 2; + __real__ b = 3.0; + __imag__ b = 4.0; +} + +template <int N> +int +f2 (void) +{ + _Complex int a; + _Complex double b; + __real__ a = 1; + __imag__ a = 2; + __real__ b = 3.0; + __imag__ b = 4.0; + return __real__ a + __imag__ b; +} + +template <int N> +_Complex double +f3 (void) +{ + _Complex int a; + _Complex double b; + __real__ a = 1; + __imag__ a = 2; + __real__ b = 3.0; + __imag__ b = 4.0; + return a + b; +} + +void +test () +{ + f1<0> (); + (void) f2<0> (); + (void) f3<0> (); +} diff --git a/gcc/testsuite/g++.dg/warn/Wunused-var-8.C b/gcc/testsuite/g++.dg/warn/Wunused-var-8.C new file mode 100644 index 0000000..69fc6fb --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-var-8.C @@ -0,0 +1,46 @@ +// { dg-do compile } +// { dg-options "-Wunused" } + +template <int N> +void +f1 (void) +{ + extern int extvari; + extvari = 1; +} + +int extvarj; + +template <int N> +void +f2 (void) +{ + extern int extvarj; + extvarj = 1; +} + +static int extvark; + +template <int N> +void +f3 (void) +{ + extern int extvark; + extvark = 1; +} + +template <int N> +int +f4 (void) +{ + return extvark; +} + +void +test () +{ + f1<0> (); + f2<0> (); + f3<0> (); + (void) f4<0> (); +} diff --git a/gcc/testsuite/gcc.dg/Wunused-var-1.c b/gcc/testsuite/gcc.dg/Wunused-var-1.c index bee34d8..d60dd70 100644 --- a/gcc/testsuite/gcc.dg/Wunused-var-1.c +++ b/gcc/testsuite/gcc.dg/Wunused-var-1.c @@ -1,179 +1,26 @@ /* { dg-do compile } */ /* { dg-options "-Wunused" } */ -void -f1 (void) -{ - int a; /* { dg-warning "set but not used" } */ - int b; - int c; - c = 1; - a = b = c; -} - -void -f2 (int x) -{ - int a; /* { dg-warning "set but not used" } */ - int b; - int c; /* { dg-warning "set but not used" } */ - c = (a = x, b = x); -} - int -f3 (int x) -{ - int a; - return a = x; -} - -int -f4 (int x) -{ - int a; - a = x; - return a; -} - -void -f5 (int x) -{ - int a[2]; /* { dg-warning "set but not used" } */ - int b; - int *c, d[2]; - c = d; - b = x; - a[b] = 1; - c[b] = 1; -} - -int -f6 (int x) -{ - int a[2]; - int b; - b = x; - a[b] = 1; - return a[b]; -} - -void -f7 (int x, int *p) -{ - int *a[2]; - a[x] = p; - a[x][x] = x; -} - -struct S { int i; }; - -void -f8 (void) -{ - struct S s; /* { dg-warning "set but not used" } */ - s.i = 6; -} - -int -f9 (void) -{ - struct S s; - s.i = 6; - return s.i; -} - -struct S -f10 (void) -{ - struct S s; - s.i = 6; - return s; -} - -extern int foo11 (int *); - -void -f11 (void) -{ - int a[2]; - foo11 (a); -} - -void -f12 (void) +f1 (void) { int a; + int foo (void) + { + return a; + } a = 1; - a; /* { dg-warning "statement with no effect" } */ + return foo (); } void -f13 (void (*x) (void)) -{ - void (*a) (void); - a = x; - a (); -} - -void -f14 (void (*x) (void)) -{ - void (*a) (void); /* { dg-warning "set but not used" } */ - a = x; -} - -extern void foo15 (int *); - -void -f15 (void) -{ - int a[10]; - int *b = a + 2; - foo15 (b); -} - -extern void foo16 (int **); - -void -f16 (void) -{ - int a[10]; - int *b[] = { a, a + 2 }; - foo16 (b); -} - -void -f17 (int x) -{ - long a; /* { dg-warning "set but not used" } */ - int b; - a = b = x; -} - -void -f18 (int x) +f2 (void) { int a; /* { dg-warning "set but not used" } */ - int b; - a = (char) (b = x); -} - -int -f19 (int x, int y, int z) -{ - int a; - int b; - a = x; - b = y; - return z ? a : b; -} - -int * -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" } */ - c[1] = 1; - return x ? a : b; + void foo (void) + { + a = 2; + } + a = 1; + foo (); } diff --git a/gcc/testsuite/gcc.dg/Wunused-var-2.c b/gcc/testsuite/gcc.dg/Wunused-var-2.c index 2818259..b5a22f8 100644 --- a/gcc/testsuite/gcc.dg/Wunused-var-2.c +++ b/gcc/testsuite/gcc.dg/Wunused-var-2.c @@ -4,17 +4,16 @@ int f1 (void) { - int c = ({ - int a; - a = 1; - a; }); - return c; -} - -void -f2 (void) -{ - int f; - f = 0; - __asm__ __volatile__ ("" : "+r" (f)); + int a; + int b; + int c; + int d; + int e; + a = 1; + b = 2; + c = 3; + d = 4; + e = 5; + return sizeof (a) + ((__typeof (b)) 1) + __alignof__ (c) + + __builtin_choose_expr (1, d, e); } diff --git a/gcc/testsuite/gcc.dg/Wunused-var-4.c b/gcc/testsuite/gcc.dg/Wunused-var-4.c deleted file mode 100644 index d60dd70..0000000 --- a/gcc/testsuite/gcc.dg/Wunused-var-4.c +++ /dev/null @@ -1,26 +0,0 @@ -/* { dg-do compile } */ -/* { dg-options "-Wunused" } */ - -int -f1 (void) -{ - int a; - int foo (void) - { - return a; - } - a = 1; - return foo (); -} - -void -f2 (void) -{ - int a; /* { dg-warning "set but not used" } */ - void foo (void) - { - a = 2; - } - a = 1; - foo (); -} diff --git a/gcc/testsuite/gcc.dg/Wunused-var-6.c b/gcc/testsuite/gcc.dg/Wunused-var-6.c deleted file mode 100644 index b5a22f8..0000000 --- a/gcc/testsuite/gcc.dg/Wunused-var-6.c +++ /dev/null @@ -1,19 +0,0 @@ -/* { dg-do compile } */ -/* { dg-options "-Wunused" } */ - -int -f1 (void) -{ - int a; - int b; - int c; - int d; - int e; - a = 1; - b = 2; - c = 3; - d = 4; - e = 5; - return sizeof (a) + ((__typeof (b)) 1) + __alignof__ (c) - + __builtin_choose_expr (1, d, e); -} |