diff options
author | Douglas Gregor <dgregor@apple.com> | 2010-10-15 13:21:21 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2010-10-15 13:21:21 +0000 |
commit | 36c22a2335c0a0aad08b84df9b101c48c8c291a3 (patch) | |
tree | c5d7f5e00388b26137e0743c8a547c71febcb93c /clang/test | |
parent | de1f58919ad113686b35113357e42e93c82f29c8 (diff) | |
download | bcm5719-llvm-36c22a2335c0a0aad08b84df9b101c48c8c291a3.tar.gz bcm5719-llvm-36c22a2335c0a0aad08b84df9b101c48c8c291a3.zip |
Diagnose C++ [class.mem]p13-14, where a class member has the same name
as the class itself. Fixes PR7082.
llvm-svn: 116573
Diffstat (limited to 'clang/test')
-rw-r--r-- | clang/test/CXX/class/class.mem/p13.cpp | 40 | ||||
-rw-r--r-- | clang/test/CXX/class/class.mem/p14.cpp | 19 | ||||
-rw-r--r-- | clang/test/SemaCXX/constructor.cpp | 3 |
3 files changed, 61 insertions, 1 deletions
diff --git a/clang/test/CXX/class/class.mem/p13.cpp b/clang/test/CXX/class/class.mem/p13.cpp new file mode 100644 index 00000000000..7cded23878e --- /dev/null +++ b/clang/test/CXX/class/class.mem/p13.cpp @@ -0,0 +1,40 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +// If T is the name of a class, then each of the following shall have +// a name different from T: + +// - every static data member of class T; +struct X0 { + static int X0; // expected-error{{member 'X0' has the same name as its class}} +}; + +// - every member function of class T +// (Cannot be tested) + +// - every member of class T that is itself a type; +struct X1 { // expected-note{{previous use is here}} + enum X1 { }; // expected-error{{use of 'X1' with tag type that does not match previous declaration}} +}; + +struct X2 { + typedef int X2; // expected-error{{member 'X2' has the same name as its class)}} +}; + +// - every enumerator of every member of class T that is an enumerated type; and +struct X3 { + enum E { + X3 // expected-error{{member 'X3' has the same name as its class}} + }; +}; + +// - every member of every anonymous union that is a member of class T. +struct X4 { + union { + int X; + union { + float Y; + unsigned X4; // expected-error{{member 'X4' has the same name as its class}} + }; + }; +}; + diff --git a/clang/test/CXX/class/class.mem/p14.cpp b/clang/test/CXX/class/class.mem/p14.cpp new file mode 100644 index 00000000000..72b232e8f71 --- /dev/null +++ b/clang/test/CXX/class/class.mem/p14.cpp @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +// In addition, if class T has a user-declared constructor (12.1), +// every non-static data member of class T shall have a name different +// from T. + +struct X0 { + int X0; // okay +}; + +struct X1 { + int X1; + X1(); // expected-error{{declarator requires an identifier}} +}; + +struct X2 { + X2(); + float X2; // expected-error{{member 'X2' has the same name as its class}} +}; diff --git a/clang/test/SemaCXX/constructor.cpp b/clang/test/SemaCXX/constructor.cpp index 9ef5c98e9e2..f3b910d2f5a 100644 --- a/clang/test/SemaCXX/constructor.cpp +++ b/clang/test/SemaCXX/constructor.cpp @@ -15,7 +15,8 @@ class Foo { virtual Foo(double); // expected-error{{constructor cannot be declared 'virtual'}} Foo(long) const; // expected-error{{'const' qualifier is not allowed on a constructor}} - int Foo(int, int); // expected-error{{constructor cannot have a return type}} + int Foo(int, int); // expected-error{{constructor cannot have a return type}} \ + // expected-error{{member 'Foo' has the same name as its class}} }; Foo::Foo(const Foo&) { } |