2009-12-16 04:14:24 +08:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
|
2008-07-01 18:37:29 +08:00
|
|
|
class C {
|
|
|
|
public:
|
|
|
|
auto int errx; // expected-error {{error: storage class specified for a member declaration}}
|
|
|
|
register int erry; // expected-error {{error: storage class specified for a member declaration}}
|
|
|
|
extern int errz; // expected-error {{error: storage class specified for a member declaration}}
|
|
|
|
|
|
|
|
static void sm() {
|
|
|
|
sx = 0;
|
|
|
|
this->x = 0; // expected-error {{error: invalid use of 'this' outside of a nonstatic member function}}
|
|
|
|
x = 0; // expected-error {{error: invalid use of member 'x' in static member function}}
|
|
|
|
}
|
|
|
|
|
|
|
|
class NestedC {
|
|
|
|
void m() {
|
|
|
|
sx = 0;
|
|
|
|
x = 0; // expected-error {{error: invalid use of nonstatic data member 'x'}}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
int b : 1, w : 2;
|
|
|
|
int : 1, : 2;
|
2009-03-06 07:01:03 +08:00
|
|
|
typedef int E : 1; // expected-error {{typedef member 'E' cannot be a bit-field}}
|
2008-07-01 18:37:29 +08:00
|
|
|
static int sb : 1; // expected-error {{error: static member 'sb' cannot be a bit-field}}
|
|
|
|
static int vs;
|
|
|
|
|
|
|
|
typedef int func();
|
|
|
|
func tm;
|
2008-10-16 04:23:22 +08:00
|
|
|
func *ptm;
|
2009-03-12 02:59:21 +08:00
|
|
|
func btm : 1; // expected-error {{bit-field 'btm' has non-integral type}}
|
|
|
|
NestedC bc : 1; // expected-error {{bit-field 'bc' has non-integral type}}
|
2008-07-01 18:37:29 +08:00
|
|
|
|
2009-01-29 01:15:10 +08:00
|
|
|
enum E1 { en1, en2 };
|
2008-07-01 18:37:29 +08:00
|
|
|
|
|
|
|
int i = 0; // expected-error {{error: 'i' can only be initialized if it is a static const integral data member}}
|
|
|
|
static int si = 0; // expected-error {{error: 'si' can only be initialized if it is a static const integral data member}}
|
|
|
|
static const NestedC ci = 0; // expected-error {{error: 'ci' can only be initialized if it is a static const integral data member}}
|
2009-03-12 07:00:04 +08:00
|
|
|
static const int nci = vs; // expected-error {{in-class initializer is not an integral constant expression}}
|
2008-07-01 18:37:29 +08:00
|
|
|
static const int vi = 0;
|
|
|
|
static const E evi = 0;
|
|
|
|
|
|
|
|
void m() {
|
|
|
|
sx = 0;
|
|
|
|
this->x = 0;
|
|
|
|
y = 0;
|
|
|
|
this = 0; // expected-error {{error: expression is not assignable}}
|
|
|
|
}
|
|
|
|
|
|
|
|
int f1(int p) {
|
2008-11-06 23:59:35 +08:00
|
|
|
A z = 6;
|
|
|
|
return p + x + this->y + z;
|
2008-07-01 18:37:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
typedef int A;
|
|
|
|
|
2009-03-12 07:00:04 +08:00
|
|
|
virtual int viv; // expected-error {{'virtual' can only appear on non-static member functions}}
|
2008-11-06 23:59:35 +08:00
|
|
|
virtual static int vsif(); // expected-error {{error: 'virtual' can only appear on non-static member functions}}
|
|
|
|
virtual int vif();
|
|
|
|
|
2008-07-01 18:37:29 +08:00
|
|
|
private:
|
|
|
|
int x,y;
|
|
|
|
static int sx;
|
2008-10-09 06:20:31 +08:00
|
|
|
|
2008-11-15 07:42:31 +08:00
|
|
|
mutable int mi;
|
|
|
|
mutable int &mir; // expected-error {{error: 'mutable' cannot be applied to references}}
|
|
|
|
mutable void mfn(); // expected-error {{error: 'mutable' cannot be applied to functions}}
|
|
|
|
mutable const int mci; // expected-error {{error: 'mutable' and 'const' cannot be mixed}}
|
|
|
|
|
2008-10-09 06:20:31 +08:00
|
|
|
static const int number = 50;
|
|
|
|
static int arr[number];
|
2008-07-01 18:37:29 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class C2 {
|
|
|
|
void f() {
|
|
|
|
static int lx;
|
|
|
|
class LC1 {
|
|
|
|
int m() { return lx; }
|
|
|
|
};
|
|
|
|
class LC2 {
|
|
|
|
int m() { return lx; }
|
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
2008-11-15 07:42:31 +08:00
|
|
|
|
2008-11-18 07:24:37 +08:00
|
|
|
struct C3 {
|
|
|
|
int i;
|
|
|
|
mutable int j;
|
|
|
|
};
|
|
|
|
void f()
|
|
|
|
{
|
|
|
|
const C3 c3 = { 1, 2 };
|
|
|
|
(void)static_cast<int*>(&c3.i); // expected-error {{static_cast from 'int const *' to 'int *' is not allowed}}
|
|
|
|
// but no error here
|
|
|
|
(void)static_cast<int*>(&c3.j);
|
|
|
|
}
|
|
|
|
|
2008-11-15 07:42:31 +08:00
|
|
|
// Play with mutable a bit more, to make sure it doesn't crash anything.
|
|
|
|
mutable int gi; // expected-error {{error: 'mutable' can only be applied to member variables}}
|
|
|
|
mutable void gfn(); // expected-error {{illegal storage class on function}}
|
|
|
|
void ogfn()
|
|
|
|
{
|
|
|
|
mutable int ml; // expected-error {{error: 'mutable' can only be applied to member variables}}
|
2008-12-28 23:28:59 +08:00
|
|
|
|
|
|
|
// PR3020: This used to crash due to double ownership of C4.
|
|
|
|
struct C4;
|
2010-04-09 05:33:23 +08:00
|
|
|
C4; // expected-warning {{declaration does not declare anything}}
|
2008-11-15 07:42:31 +08:00
|
|
|
}
|
Unify the code for defining tags in C and C++, so that we always
introduce a Scope for the body of a tag. This reduces the number of
semantic differences between C and C++ structs and unions, and will
help with other features (e.g., anonymous unions) in C. Some important
points:
- Fields are now in the "member" namespace (IDNS_Member), to keep
them separate from tags and ordinary names in C. See the new test
in Sema/member-reference.c for an example of why this matters. In
C++, ordinary and member name lookup will find members in both the
ordinary and member namespace, so the difference between
IDNS_Member and IDNS_Ordinary is erased by Sema::LookupDecl (but
only in C++!).
- We always introduce a Scope and push a DeclContext when we're
defining a tag, in both C and C++. Previously, we had different
actions and different Scope/CurContext behavior for enums, C
structs/unions, and C++ structs/unions/classes. Now, it's one pair
of actions. (Yay!)
There's still some fuzziness in the handling of struct/union/enum
definitions within other struct/union/enum definitions in C. We'll
need to do some more cleanup to eliminate some reliance on CurContext
before we can solve this issue for real. What we want is for something
like this:
struct X {
struct T { int x; } t;
};
to introduce T into translation unit scope (placing it at the
appropriate point in the IdentifierResolver chain, too), but it should
still have struct X as its lexical declaration
context. PushOnScopeChains isn't smart enough to do that yet, though,
so there's a FIXME test in nested-redef.c
llvm-svn: 61940
2009-01-09 04:45:30 +08:00
|
|
|
|
|
|
|
struct C4 {
|
|
|
|
void f(); // expected-note{{previous declaration is here}}
|
|
|
|
int f; // expected-error{{duplicate member 'f'}}
|
|
|
|
};
|
2009-11-25 01:14:34 +08:00
|
|
|
|
|
|
|
// PR5415 - don't hang!
|
|
|
|
struct S
|
|
|
|
{
|
2009-11-25 07:38:44 +08:00
|
|
|
void f(); // expected-note 1 {{previous declaration}}
|
|
|
|
void S::f() {} // expected-error {{class member cannot be redeclared}} expected-note {{previous declaration}} expected-note {{previous definition}}
|
2009-11-25 01:14:34 +08:00
|
|
|
void f() {} // expected-error {{class member cannot be redeclared}} expected-error {{redefinition}}
|
|
|
|
};
|
2010-03-17 09:31:25 +08:00
|
|
|
|
|
|
|
// Don't crash on this bogus code.
|
|
|
|
namespace pr6629 {
|
|
|
|
// TODO: most of these errors are spurious
|
|
|
|
template<class T1, class T2> struct foo :
|
|
|
|
bogus<foo<T1,T2> > // expected-error {{unknown template name 'bogus'}} \
|
|
|
|
// BOGUS expected-error {{expected '{' after base class list}} \
|
|
|
|
// BOGUS expected-error {{expected ';' after struct}} \
|
|
|
|
// BOGUS expected-error {{expected unqualified-id}} \
|
|
|
|
{ };
|
|
|
|
|
|
|
|
template<> struct foo<unknown,unknown> { // why isn't there an error here?
|
|
|
|
template <typename U1, typename U2> struct bar {
|
|
|
|
typedef bar type;
|
|
|
|
static const int value = 0;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
2010-05-18 02:19:56 +08:00
|
|
|
|
|
|
|
namespace PR7153 {
|
|
|
|
class EnclosingClass {
|
|
|
|
struct A { } mutable *member;
|
|
|
|
};
|
|
|
|
}
|