aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/g++.dg/warn/Wunused-local-typedefs.C
blob: 4fc8640ed7b2337ed2986a3038ebee48556bc669 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// Origin PR c++/33255
// { dg-options "-Wunused" } <-- should trigger -Wunused-local-typedefs
// { dg-do compile }

void
test_warn()
{
  typedef int foo; // { dg-warning "locally defined but not used" }
}

struct S
{
    typedef int T;
    S() {}
    S(int) {}
};

template<class T>
struct ST
{
    typedef T type;
    ST (int) {}
    ST () {}
};

template<class T>
void
test0_tmpl(void)
{
    typedef struct ST<T> foo;
    foo(2);
}

int
test0(void)
{
    test0_tmpl<int>();
}

void
test1(void)
{
    typedef int foo;
    ST<foo> a;
}


int
test2(void)
{
    typedef S foo;
    foo::T i = 0;
    return i;
}

template<class T>
void
test3_tmpl(void)
{
    typedef struct ST<int> foo;
    ST<int> v;
    const foo __attribute__((unused))&var = v;
}

void
test3(void)
{
    test3_tmpl<int>();
}

void
test4(void)
{
  typedef int foo;
  int __attribute__((unused))vec[1] = {sizeof (foo)};
}

void
test5(void)
{
  typedef int T0;
  typedef char T1;
  typedef int* T2;
  typedef unsigned T3;
  struct C0 { virtual void f(void) {}};
  struct C1 : C0 {};
  typedef C0 T4;

  int v0 = (T0) 2;
  char __attribute__((unused)) v1 = static_cast<T1> (0);
  if (reinterpret_cast<T2> (&v0));
  unsigned* const c = 0;
  unsigned* __attribute__((unused))v2 = const_cast<T3* const> (c);
  C0 *__attribute__((unused))p0 = 0;
  C1 *p1 = 0;
  p0 = dynamic_cast<T4*> (p1);  
}

void
test6(void)
{
  struct C0 {};
  typedef C0 foo;
  C0 *__attribute__((unused))v = new foo;
}

template<class T, class U>
struct S7
{
  void
  f()
  {
    typedef int foo;
    sizeof(foo);
  }
};

template<class T>
void
test7(void)
{
  typedef typename ST<T>::T bar; // { dg-warning "locally defined but not used" }
  typedef typename ST<T>::T foo; // We shouldn't warn for this one, as
				 // it's used below.
  S7<int, foo> v;
}


template<class T, class U>
void
test8(void)
{
  int f(S7<T, U>);
  void g(int);
  typedef T foo;
  g(f(S7<foo, U>()));
}

int
test9(void)
{
  struct s { typedef int foo;}; // { dg-warning "locally defined but not used" }
  struct t { typedef int bar;};
  t::bar b = 0;
  return b;
}