1 // PR c++/79548 - missing -Wunused-variable on a typedef'd variable 2 // in a function template 3 // { dg-do compile } 4 // { dg-options "-Wunused" } 5 6 7 #define UNUSED __attribute__ ((unused)) 8 9 template <class T> f_int()10void f_int () 11 { 12 T t; // { dg-warning "unused variable" } 13 14 typedef T U; 15 U u; // { dg-warning "unused variable" } 16 } 17 18 template void f_int<int>(); 19 20 21 template <class T> f_intptr()22void f_intptr () 23 { 24 T *t = 0; // { dg-warning "unused variable" } 25 26 typedef T U; 27 U *u = 0; // { dg-warning "unused variable" } 28 } 29 30 template void f_intptr<int>(); 31 32 33 template <class T> f_var_unused()34void f_var_unused () 35 { 36 // The variable is marked unused. 37 T t UNUSED; 38 39 typedef T U; 40 U u UNUSED; 41 } 42 43 template void f_var_unused<int>(); 44 45 46 template <class T> f_var_type_unused()47void f_var_type_unused () 48 { 49 // The variable's type is marked unused. 50 T* UNUSED t = new T; // { dg-bogus "unused variable" "bug 79585" } 51 52 typedef T U; 53 U* UNUSED u = new U; // { dg-bogus "unused variable" "bug 79585" } 54 55 typedef T UNUSED U; 56 U v = U (); // { dg-bogus "unused variable" "bug 79585" } 57 } 58 59 template void f_var_type_unused<int>(); 60 61 62 struct A { int i; }; 63 64 template <class T> f_A()65void f_A () 66 { 67 T t; // { dg-warning "unused variable" } 68 69 typedef T U; 70 U u; // { dg-warning "unused variable" } 71 } 72 73 template void f_A<A>(); 74 75 76 template <class T> f_A_unused()77void f_A_unused () 78 { 79 T t UNUSED; 80 81 typedef T U; 82 U u UNUSED; 83 } 84 85 template void f_A_unused<A>(); 86 87 88 struct B { B (); }; 89 90 template <class T> f_B()91void f_B () 92 { 93 T t; 94 95 typedef T U; 96 U u; 97 } 98 99 template void f_B<B>(); 100 101 102 struct NonTrivialDtor { ~NonTrivialDtor (); }; 103 104 template <class T> f_with_NonTrivialDtor()105void f_with_NonTrivialDtor () 106 { 107 // Expect no warnings when instantiated on a type with a non-trivial 108 // destructor. 109 T t; 110 111 typedef T U; 112 U u; 113 } 114 115 template void f_with_NonTrivialDtor<NonTrivialDtor>(); 116 117 118 struct D { NonTrivialDtor b; }; 119 120 template <class T> f_D()121void f_D () 122 { 123 // Same as f_with_NonTrivialDtor but with a class that has a member 124 // with a non-trivial dtor. 125 T t; 126 127 typedef T U; 128 U u; 129 } 130 131 template void f_D<D>(); 132 133 134 struct UNUSED DeclaredUnused { }; 135 136 template <class T> f_with_unused()137void f_with_unused () 138 { 139 // Expect no warnings when instantiatiated on a type declared 140 // with attribute unused. 141 T t; 142 143 typedef T U; 144 U u; 145 } 146 147 template void f_with_unused<DeclaredUnused>(); 148