2017-04-04 00:43:21 +08:00
|
|
|
// RUN: %clang_cc1 -verify -fsyntax-only -std=c++11 -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}}
|
2017-04-04 00:43:21 +08:00
|
|
|
typedef int jj; // expected-note 2 {{previous declaration is here}}
|
|
|
|
using jjj=int; // expected-note 2 {{previous declaration is here}}
|
2010-03-17 05:50:59 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace xx {
|
|
|
|
int m;
|
2017-04-04 00:43:21 +08:00
|
|
|
typedef int mm;
|
|
|
|
using mmm=int;
|
|
|
|
|
2010-03-17 05:50:59 +08:00
|
|
|
}
|
|
|
|
namespace yy {
|
|
|
|
int m;
|
2017-04-04 00:43:21 +08:00
|
|
|
typedef char mm;
|
|
|
|
using mmm=char;
|
2010-03-17 05:50:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2017-04-04 00:43:21 +08:00
|
|
|
int mm;
|
|
|
|
int mmm;
|
2010-03-17 05:50:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
class A {
|
2017-04-04 00:43:21 +08:00
|
|
|
static int data; // expected-note 1 {{previous declaration}}
|
|
|
|
// expected-note@+1 1 {{previous declaration}}
|
2016-04-29 08:37:43 +08:00
|
|
|
int field;
|
|
|
|
int f1, f2, f3, f4; // expected-note 8 {{previous declaration is here}}
|
|
|
|
|
2017-04-04 00:43:21 +08:00
|
|
|
typedef int a1; // expected-note 2 {{previous declaration}}
|
|
|
|
using a2=int; // expected-note 2 {{previous declaration}}
|
|
|
|
|
2016-04-29 08:37:43 +08:00
|
|
|
// 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'}}
|
2017-04-04 00:43:21 +08:00
|
|
|
char *a1; // no warning
|
|
|
|
char *a2; // no warning
|
|
|
|
char *jj; // no warning
|
|
|
|
char *jjj; // no warning
|
|
|
|
}
|
|
|
|
|
|
|
|
void test2() {
|
|
|
|
typedef char field; // no warning
|
|
|
|
typedef char data; // no warning
|
|
|
|
typedef char a1; // expected-warning {{declaration shadows a typedef in 'A'}}
|
|
|
|
typedef char a2; // expected-warning {{declaration shadows a type alias in 'A'}}
|
|
|
|
typedef char jj; // expected-warning {{declaration shadows a typedef in namespace 'one::two'}}
|
|
|
|
typedef char jjj; // expected-warning {{declaration shadows a type alias in namespace 'one::two'}}
|
|
|
|
}
|
|
|
|
|
|
|
|
void test3() {
|
|
|
|
using field=char; // no warning
|
|
|
|
using data=char; // no warning
|
|
|
|
using a1=char; // expected-warning {{declaration shadows a typedef in 'A'}}
|
|
|
|
using a2=char; // expected-warning {{declaration shadows a type alias in 'A'}}
|
|
|
|
using jj=char; // expected-warning {{declaration shadows a typedef in namespace 'one::two'}}
|
|
|
|
using jjj=char; // expected-warning {{declaration shadows a type alias in namespace 'one::two'}}
|
2010-03-17 05:50:59 +08:00
|
|
|
}
|
|
|
|
};
|
2010-03-20 12:12:52 +08:00
|
|
|
|
2017-04-05 16:36:58 +08:00
|
|
|
struct path {
|
|
|
|
using value_type = char;
|
|
|
|
typedef char value_type2;
|
|
|
|
struct iterator {
|
|
|
|
using value_type = path; // no warning
|
|
|
|
typedef path value_type2; // no warning
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
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();
|
2017-04-04 00:43:21 +08:00
|
|
|
static void Baz1();
|
|
|
|
static void Baz2();
|
2011-01-31 15:04:54 +08:00
|
|
|
private:
|
|
|
|
int Bar;
|
|
|
|
};
|
|
|
|
|
|
|
|
void Foo::Baz() {
|
|
|
|
double Bar = 12; // Don't warn.
|
|
|
|
}
|
2017-04-04 00:43:21 +08:00
|
|
|
|
|
|
|
void Foo::Baz1() {
|
|
|
|
typedef int Bar; // Don't warn.
|
|
|
|
}
|
|
|
|
|
|
|
|
void Foo::Baz2() {
|
|
|
|
using Bar=int; // Don't warn.
|
|
|
|
}
|
2011-01-31 15:04:54 +08:00
|
|
|
}
|
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
|
|
|
|
2017-04-04 00:43:21 +08:00
|
|
|
extern int bob; // expected-note 1 {{previous declaration is here}}
|
|
|
|
typedef int bob1; // expected-note 2 {{previous declaration is here}}
|
|
|
|
using bob2=int; // expected-note 2 {{previous declaration is here}}
|
2011-04-26 05:39:50 +08:00
|
|
|
|
|
|
|
// 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}}
|
2017-04-04 00:43:21 +08:00
|
|
|
int bob1; //no warning
|
|
|
|
int bob2; // no warning
|
|
|
|
}
|
|
|
|
|
|
|
|
void test9() {
|
|
|
|
typedef int bob; // no warning
|
|
|
|
typedef int bob1; // expected-warning {{declaration shadows a typedef in the global namespace}}
|
|
|
|
typedef int bob2; // expected-warning {{declaration shadows a type alias in the global namespace}}
|
|
|
|
}
|
|
|
|
|
|
|
|
void test10() {
|
|
|
|
using bob=int; // no warning
|
|
|
|
using bob1=int; // expected-warning {{declaration shadows a typedef in the global namespace}}
|
|
|
|
using bob2=int; // expected-warning {{declaration shadows a type alias in the global namespace}}
|
2011-04-26 05:39:50 +08:00
|
|
|
}
|
2017-01-10 22:41:13 +08:00
|
|
|
|
|
|
|
namespace rdar29067894 {
|
|
|
|
|
|
|
|
void avoidWarningWhenRedefining(int b) { // expected-note {{previous definition is here}}
|
|
|
|
int a = 0; // expected-note {{previous definition is here}}
|
|
|
|
int a = 1; // expected-error {{redefinition of 'a'}}
|
|
|
|
int b = 2; // expected-error {{redefinition of 'b'}}
|
2017-04-04 00:43:21 +08:00
|
|
|
|
|
|
|
using c=char; // expected-note {{previous definition is here}}
|
|
|
|
using c=int; // expected-error {{type alias redefinition with different types ('int' vs 'char')}}
|
|
|
|
|
|
|
|
typedef char d; // expected-note {{previous definition is here}}
|
|
|
|
typedef int d; // expected-error {{typedef redefinition with different types ('int' vs 'char')}}
|
|
|
|
|
|
|
|
using e=char; // expected-note {{previous definition is here}}
|
|
|
|
typedef int e; // expected-error {{type alias redefinition with different types ('int' vs 'char')}}
|
|
|
|
|
|
|
|
int f; // expected-note {{previous definition is here}}
|
|
|
|
using f=int; // expected-error {{redefinition of 'f'}}
|
|
|
|
|
|
|
|
using g=int; // expected-note {{previous definition is here}}
|
|
|
|
int g; // expected-error {{redefinition of 'g'}}
|
|
|
|
|
|
|
|
typedef int h; // expected-note {{previous definition is here}}
|
|
|
|
int h; // expected-error {{redefinition of 'h'}}
|
|
|
|
|
|
|
|
int k; // expected-note {{previous definition is here}}
|
|
|
|
typedef int k; // expected-error {{redefinition of 'k'}}
|
|
|
|
|
|
|
|
using l=char; // no warning or error.
|
|
|
|
using l=char; // no warning or error.
|
|
|
|
typedef char l; // no warning or error.
|
|
|
|
|
|
|
|
typedef char n; // no warning or error.
|
|
|
|
typedef char n; // no warning or error.
|
|
|
|
using n=char; // no warning or error.
|
2017-01-10 22:41:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
Fix an assertion failure in FormatASTNodeDiagnosticArgument.
Summary:
The test being added in this patch used to cause an assertion failure:
/build/./bin/clang -cc1 -internal-isystem /build/lib/clang/5.0.0/include -nostdsysteminc -verify -fsyntax-only -std=c++11 -Wshadow-all /src/tools/clang/test/SemaCXX/warn-shadow.cpp
--
Exit Code: 134
Command Output (stderr):
--
clang: /src/tools/clang/lib/AST/ASTDiagnostic.cpp:424: void clang::FormatASTNodeDiagnosticArgument(DiagnosticsEngine::ArgumentKind, intptr_t, llvm::StringRef, llvm::StringRef, ArrayRef<DiagnosticsEngine::ArgumentValue>, SmallVectorImpl<char> &, void *, ArrayRef<intptr_t>): Assertion `isa<NamedDecl>(DC) && "Expected a NamedDecl"' failed.
#0 0x0000000001c7a1b4 PrintStackTraceSignalHandler(void*) (/build/./bin/clang+0x1c7a1b4)
#1 0x0000000001c7a4e6 SignalHandler(int) (/build/./bin/clang+0x1c7a4e6)
#2 0x00007f30880078d0 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0xf8d0)
#3 0x00007f3087054067 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x35067)
#4 0x00007f3087055448 abort (/lib/x86_64-linux-gnu/libc.so.6+0x36448)
#5 0x00007f308704d266 (/lib/x86_64-linux-gnu/libc.so.6+0x2e266)
#6 0x00007f308704d312 (/lib/x86_64-linux-gnu/libc.so.6+0x2e312)
#7 0x00000000035b7f22 clang::FormatASTNodeDiagnosticArgument(clang::DiagnosticsEngine::ArgumentKind, long, llvm::StringRef, llvm::StringRef, llvm::ArrayRef<std::pair<clang::DiagnosticsEngine::ArgumentKind, long> >, llvm::SmallVectorImpl<char>&, void*, llvm::ArrayRef<long>) (/build/
./bin/clang+0x35b7f22)
#8 0x0000000001ddbae4 clang::Diagnostic::FormatDiagnostic(char const*, char const*, llvm::SmallVectorImpl<char>&) const (/build/./bin/clang+0x1ddbae4)
#9 0x0000000001ddb323 clang::Diagnostic::FormatDiagnostic(char const*, char const*, llvm::SmallVectorImpl<char>&) const (/build/./bin/clang+0x1ddb323)
#10 0x00000000022878a4 clang::TextDiagnosticBuffer::HandleDiagnostic(clang::DiagnosticsEngine::Level, clang::Diagnostic const&) (/build/./bin/clang+0x22878a4)
#11 0x0000000001ddf387 clang::DiagnosticIDs::ProcessDiag(clang::DiagnosticsEngine&) const (/build/./bin/clang+0x1ddf387)
#12 0x0000000001dd9dea clang::DiagnosticsEngine::EmitCurrentDiagnostic(bool) (/build/./bin/clang+0x1dd9dea)
#13 0x0000000002cad00c clang::Sema::EmitCurrentDiagnostic(unsigned int) (/build/./bin/clang+0x2cad00c)
#14 0x0000000002d91cd2 clang::Sema::CheckShadow(clang::NamedDecl*, clang::NamedDecl*, clang::LookupResult const&) (/build/./bin/clang+0x2d91cd2)
Stack dump:
0. Program arguments: /build/./bin/clang -cc1 -internal-isystem /build/lib/clang/5.0.0/include -nostdsysteminc -verify -fsyntax-only -std=c++11 -Wshadow-all /src/tools/clang/test/SemaCXX/warn-shadow.cpp
1. /src/tools/clang/test/SemaCXX/warn-shadow.cpp:214:23: current parser token ';'
2. /src/tools/clang/test/SemaCXX/warn-shadow.cpp:213:26: parsing function body 'handleLinkageSpec'
3. /src/tools/clang/test/SemaCXX/warn-shadow.cpp:213:26: in compound statement ('{}')
/build/tools/clang/test/SemaCXX/Output/warn-shadow.cpp.script: line 1: 15595 Aborted (core dumped) /build/./bin/clang -cc1 -internal-isystem /build/lib/clang/5.0.0/include -nostdsysteminc -verify -fsyntax-only -std=c++11 -Wshadow-all /src/tools/clang/test/SemaCXX/warn-shadow.cpp
Reviewers: rsmith
Reviewed By: rsmith
Subscribers: krytarowski, cfe-commits
Differential Revision: https://reviews.llvm.org/D33207
llvm-svn: 303325
2017-05-18 11:02:15 +08:00
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
typedef int externC; // expected-note {{previous declaration is here}}
|
|
|
|
}
|
|
|
|
void handleLinkageSpec() {
|
|
|
|
typedef void externC; // expected-warning {{declaration shadows a typedef in the global namespace}}
|
|
|
|
}
|
2017-07-31 23:21:26 +08:00
|
|
|
|
|
|
|
namespace PR33947 {
|
|
|
|
void f(int a) {
|
|
|
|
struct A {
|
|
|
|
void g(int a) {}
|
|
|
|
A() { int a; }
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
2018-10-12 00:40:18 +08:00
|
|
|
|
|
|
|
int PR24718;
|
|
|
|
enum class X { PR24718 }; // Ok, not shadowing
|