aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/g++.dg/warn/Wshadow-local-2.C
blob: ac3951ebcd01932cd84fa2b8217531ce003ec353 (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
/* { dg-do compile } */
/* { dg-options -Wshadow-local } */

class Bar {
};

class ChildBar : public Bar {
};

Bar bar;             // { dg-bogus "shadowed declaration" }

class Foo {
 private:
  int val;

 public:
  int func1(int x) {
    int val;         // { dg-bogus "shadows a member" }
    val = x;
    return val;
  }

  int func2(int i) { // { dg-warning "shadowed declaration" }
    int a = 3;       // { dg-warning "shadowed declaration" }

    for (int i = 0; i < 5; ++i) {   // { dg-warning "shadows a parameter" }
      for (int i = 0; i < 3; ++i) { // { dg-warning "shadows a previous local" }
        int a = i;   // { dg-warning "shadows a previous local" }
        func1(a);
      }
    }

    return a;
  }

  int func3() {
    int bar;         // { dg-bogus "shadows a global" }
    float func1 = 0.3; // { dg-bogus "shadows a member" }
    int f = 5;       // { dg-warning "shadowed declaration" }

    if (func1 > 1) {
      float f = 2.0; // { dg-warning "shadows a previous local" }
      bar = f;
    }
    else
      bar = 1;
    return bar;
  }

  void func4() {
    Bar *bar;        // { dg-warning "shadowed declaration" }
    ChildBar *cbp;   // { dg-warning "shadowed declaration" }
    Bar *bp;         // { dg-warning "shadowed declaration" }
    if (val) {
      int bar;       // { dg-warning "shadows a previous local" }
      Bar *cbp;      // { dg-warning "shadows a previous local" }
      ChildBar *bp;  // { dg-warning "shadows a previous local" }
      func1(bar);
    }
  }
};

// { dg-warning "shadowed declaration" "" { target *-*-* } 26 }