cxx-decl.cpp revision eab9d6f9065b042d39fbaf9842c9d8cc968dd6d0
1// RUN: %clang_cc1 -verify -fsyntax-only -triple i386-linux -pedantic %s
2
3int x(*g); // expected-error {{use of undeclared identifier 'g'}}
4
5struct Type {
6  int Type;
7};
8
9// rdar://8365458
10// rdar://9132143
11typedef char bool; // expected-error {{redeclaration of C++ built-in type 'bool'}}
12
13// PR4451 - We should recover well from the typo of '::' as ':' in a2.
14namespace y {
15  struct a { };
16  typedef int b;
17}
18
19y::a a1;
20y:a a2;  // expected-error {{unexpected ':' in nested name specifier}}
21y::a a3 = a2;
22
23// Some valid colons:
24void foo() {
25y:  // label
26  y::a s;
27
28  int a = 4;
29  a = a ? a : a+1;
30}
31
32struct b : y::a {};
33
34template <typename T>
35class someclass {
36
37  int bar() {
38    T *P;
39    return 1 ? P->x : P->y;
40  }
41};
42
43class asm_class_test {
44  void foo() __asm__("baz");
45};
46
47enum { fooenum = 1, }; // expected-warning {{commas at the end of enumerator lists are a C++11 extension}}
48
49struct a {
50  int Type : fooenum;
51};
52
53void test(struct Type *P) {
54  int Type;
55  Type = 1 ? P->Type : Type;
56
57  Type = (y:b) 4;   // expected-error {{unexpected ':' in nested name specifier}}
58  Type = 1 ? (
59              (y:b)  // expected-error {{unexpected ':' in nested name specifier}}
60              4) : 5;
61}
62
63struct test4 {
64  int x  // expected-error {{expected ';' at end of declaration list}}
65  int y;
66  int z  // expected-error {{expected ';' at end of declaration list}}
67};
68
69// Make sure we know these are legitimate commas and not typos for ';'.
70namespace Commas {
71  struct S {
72    static int a;
73    int c,
74    operator()();
75  };
76
77  int global1,
78  __attribute__(()) global2,
79  (global5),
80  *global6,
81  &global7 = global1,
82  &&global8 = static_cast<int&&>(global1), // expected-warning 2{{rvalue reference}}
83  S::a,
84  global9,
85  global10 = 0,
86  global11 == 0, // expected-error {{did you mean '='}}
87  global12 __attribute__(()),
88  global13(0),
89  global14[2],
90  global15;
91
92  void g() {
93    static int a,
94    b __asm__("ebx"), // expected-error {{expected ';' at end of declaration}}
95    Statics:return;
96  }
97}
98
99// PR5825
100struct test5 {};
101::new(static_cast<void*>(0)) test5; // expected-error {{expected unqualified-id}}
102
103
104// PR6782
105template<class T>
106class Class1;
107
108class Class2 {
109}  // no ;
110
111typedef Class1<Class2> Type1; // expected-error {{cannot combine with previous 'class' declaration specifier}}
112
113// rdar : // 8307865
114struct CodeCompleteConsumer {
115};
116
117void CodeCompleteConsumer::() { // expected-error {{xpected unqualified-id}}
118}
119
120;
121
122// PR8380
123extern ""      // expected-error {{unknown linkage language}}
124test6a { ;// expected-error {{C++ requires a type specifier for all declarations}} \
125     // expected-error {{expected ';' after top level declarator}}
126
127  int test6b;
128