2016-04-29 08:37:43 +08:00
|
|
|
// RUN: %clang_cc1 -verify -fsyntax-only -Wshadow-all %s
|
2010-03-17 05:50:59 +08:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
int i; // expected-note {{previous declaration is here}}
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace one {
|
|
|
|
namespace two {
|
|
|
|
int j; // expected-note {{previous declaration is here}}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace xx {
|
|
|
|
int m;
|
|
|
|
}
|
|
|
|
namespace yy {
|
|
|
|
int m;
|
|
|
|
}
|
|
|
|
|
|
|
|
using namespace one::two;
|
|
|
|
using namespace xx;
|
|
|
|
using namespace yy;
|
|
|
|
|
|
|
|
void foo() {
|
2014-04-02 13:58:29 +08:00
|
|
|
int i; // expected-warning {{declaration shadows a variable in namespace '(anonymous)'}}
|
2010-03-17 05:50:59 +08:00
|
|
|
int j; // expected-warning {{declaration shadows a variable in namespace 'one::two'}}
|
|
|
|
int m;
|
|
|
|
}
|
|
|
|
|
|
|
|
class A {
|
|
|
|
static int data; // expected-note {{previous declaration}}
|
2016-04-29 08:37:43 +08:00
|
|
|
// expected-note@+1 {{previous declaration}}
|
|
|
|
int field;
|
|
|
|
int f1, f2, f3, f4; // expected-note 8 {{previous declaration is here}}
|
|
|
|
|
|
|
|
// The initialization is safe, but the modifications are not.
|
|
|
|
A(int f1, int f2, int f3, int f4) // expected-note-re 4 {{variable 'f{{[0-4]}}' is declared here}}
|
|
|
|
: f1(f1) {
|
|
|
|
f1 = 3; // expected-warning {{modifying constructor parameter 'f1' that shadows a field of 'A'}}
|
|
|
|
f1 = 4; // one warning per shadow
|
|
|
|
f2++; // expected-warning {{modifying constructor parameter 'f2' that shadows a field of 'A'}}
|
|
|
|
--f3; // expected-warning {{modifying constructor parameter 'f3' that shadows a field of 'A'}}
|
|
|
|
f4 += 2; // expected-warning {{modifying constructor parameter 'f4' that shadows a field of 'A'}}
|
|
|
|
}
|
|
|
|
|
|
|
|
// The initialization is safe, but the modifications are not.
|
|
|
|
// expected-warning-re@+1 4 {{constructor parameter 'f{{[0-4]}}' shadows the field 'f{{[0-9]}}' of 'A'}}
|
|
|
|
A(int f1, int f2, int f3, int f4, double overload_dummy) {}
|
2010-03-17 05:50:59 +08:00
|
|
|
|
|
|
|
void test() {
|
|
|
|
char *field; // expected-warning {{declaration shadows a field of 'A'}}
|
|
|
|
char *data; // expected-warning {{declaration shadows a static data member of 'A'}}
|
|
|
|
}
|
|
|
|
};
|
2010-03-20 12:12:52 +08:00
|
|
|
|
|
|
|
// TODO: this should warn, <rdar://problem/5018057>
|
|
|
|
class B : A {
|
|
|
|
int data;
|
|
|
|
static int field;
|
|
|
|
};
|
2011-01-31 15:04:54 +08:00
|
|
|
|
|
|
|
// rdar://8900456
|
|
|
|
namespace rdar8900456 {
|
|
|
|
struct Foo {
|
|
|
|
static void Baz();
|
|
|
|
private:
|
|
|
|
int Bar;
|
|
|
|
};
|
|
|
|
|
|
|
|
void Foo::Baz() {
|
|
|
|
double Bar = 12; // Don't warn.
|
|
|
|
}
|
|
|
|
}
|
2011-02-09 02:21:25 +08:00
|
|
|
|
|
|
|
// http://llvm.org/PR9160
|
|
|
|
namespace PR9160 {
|
|
|
|
struct V {
|
|
|
|
V(int);
|
|
|
|
};
|
|
|
|
struct S {
|
|
|
|
V v;
|
|
|
|
static void m() {
|
|
|
|
if (1) {
|
|
|
|
V v(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2011-04-26 05:39:50 +08:00
|
|
|
|
|
|
|
extern int bob; // expected-note {{previous declaration is here}}
|
|
|
|
|
|
|
|
// rdar://8883302
|
|
|
|
void rdar8883302() {
|
|
|
|
extern int bob; // don't warn for shadowing.
|
|
|
|
}
|
|
|
|
|
|
|
|
void test8() {
|
|
|
|
int bob; // expected-warning {{declaration shadows a variable in the global namespace}}
|
|
|
|
}
|