Douglas Gregor | b6bf544 | 2008-12-16 06:37:47 +0000 | [diff] [blame] | 1 | // RUN: clang -fsyntax-only -verify -std=c++98 %s |
Argiris Kirtzidis | 054a263 | 2008-11-08 17:17:31 +0000 | [diff] [blame] | 2 | namespace A { |
| 3 | struct C { |
| 4 | static int cx; |
| 5 | }; |
| 6 | int ax; |
| 7 | void Af(); |
| 8 | } |
| 9 | |
| 10 | A:: ; // expected-error {{expected unqualified-id}} |
| 11 | ::A::ax::undef ex3; // expected-error {{expected a class or namespace}} expected-error {{expected '=', ',', ';', 'asm', or '__attribute__' after declarator}} |
| 12 | A::undef1::undef2 ex4; // expected-error {{no member named 'undef1'}} expected-error {{expected '=', ',', ';', 'asm', or '__attribute__' after declarator}} |
| 13 | |
| 14 | class C2 { |
Douglas Gregor | c5cbc24 | 2008-12-15 23:53:10 +0000 | [diff] [blame] | 15 | void m(); // expected-note{{member declaration nearly matches}} |
| 16 | |
| 17 | void f(const int& parm); // expected-note{{member declaration nearly matches}} |
| 18 | void f(int) const; // expected-note{{member declaration nearly matches}} |
| 19 | void f(float); |
| 20 | |
Argiris Kirtzidis | 054a263 | 2008-11-08 17:17:31 +0000 | [diff] [blame] | 21 | int x; |
| 22 | }; |
| 23 | |
Douglas Gregor | c5cbc24 | 2008-12-15 23:53:10 +0000 | [diff] [blame] | 24 | void C2::m() const { } // expected-error{{out-of-line definition does not match any declaration in 'C2'}} |
| 25 | |
| 26 | void C2::f(int) { } // expected-error{{out-of-line definition does not match any declaration in 'C2'}} |
| 27 | |
Argiris Kirtzidis | 054a263 | 2008-11-08 17:17:31 +0000 | [diff] [blame] | 28 | void C2::m() { |
| 29 | x = 0; |
| 30 | } |
| 31 | |
| 32 | namespace B { |
Chris Lattner | 254de7d | 2008-11-23 20:28:15 +0000 | [diff] [blame] | 33 | void ::A::Af() {} // expected-error {{definition or redeclaration of 'Af' not in a namespace enclosing 'A'}} |
Argiris Kirtzidis | 054a263 | 2008-11-08 17:17:31 +0000 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | void f1() { |
Douglas Gregor | c5cbc24 | 2008-12-15 23:53:10 +0000 | [diff] [blame] | 37 | void A::Af(); // expected-error {{definition or redeclaration of 'Af' not allowed inside a function}} |
Argiris Kirtzidis | 054a263 | 2008-11-08 17:17:31 +0000 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | void f2() { |
| 41 | A:: ; // expected-error {{expected unqualified-id}} |
| 42 | A::C::undef = 0; // expected-error {{no member named 'undef'}} |
| 43 | ::A::C::cx = 0; |
| 44 | int x = ::A::ax = A::C::cx; |
| 45 | x = sizeof(A::C); |
| 46 | x = sizeof(::A::C::cx); |
| 47 | } |
| 48 | |
| 49 | A::C c1; |
| 50 | struct A::C c2; |
| 51 | struct S : public A::C {}; |
| 52 | struct A::undef; // expected-error {{'undef' does not name a tag member in the specified scope}} |
| 53 | |
Argiris Kirtzidis | 881964b | 2008-11-09 23:41:00 +0000 | [diff] [blame] | 54 | namespace A2 { |
| 55 | typedef int INT; |
| 56 | struct RC; |
Argiris Kirtzidis | 9cd599b | 2008-11-19 18:01:13 +0000 | [diff] [blame] | 57 | struct CC { |
| 58 | struct NC; |
| 59 | }; |
Argiris Kirtzidis | 881964b | 2008-11-09 23:41:00 +0000 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | struct A2::RC { |
| 63 | INT x; |
| 64 | }; |
| 65 | |
Argiris Kirtzidis | 9cd599b | 2008-11-19 18:01:13 +0000 | [diff] [blame] | 66 | struct A2::CC::NC { |
| 67 | void m() {} |
| 68 | }; |
| 69 | |
Argiris Kirtzidis | 054a263 | 2008-11-08 17:17:31 +0000 | [diff] [blame] | 70 | void f3() { |
| 71 | N::x = 0; // expected-error {{use of undeclared identifier 'N'}} |
| 72 | int N; |
| 73 | N::x = 0; // expected-error {{expected a class or namespace}} |
| 74 | { int A; A::ax = 0; } |
Douglas Gregor | b6bf544 | 2008-12-16 06:37:47 +0000 | [diff] [blame] | 75 | { typedef int A; A::ax = 0; } // expected-error{{expected a class or namespace}} |
| 76 | { int A(); A::ax = 0; } |
Argiris Kirtzidis | 054a263 | 2008-11-08 17:17:31 +0000 | [diff] [blame] | 77 | { typedef A::C A; A::ax = 0; } // expected-error {{no member named 'ax'}} |
| 78 | { typedef A::C A; A::cx = 0; } |
| 79 | } |
Argiris Kirtzidis | 4c642e1 | 2008-11-19 15:22:16 +0000 | [diff] [blame] | 80 | |
| 81 | // make sure the following doesn't hit any asserts |
Chris Lattner | 921342c | 2008-11-23 23:17:07 +0000 | [diff] [blame] | 82 | void f4(undef::C); // expected-error {{use of undeclared identifier 'undef'}} // expected-error {{expected ')'}} expected-note {{to match this '('}} // expected-error {{variable has incomplete type 'void'}} |
Douglas Gregor | c5cbc24 | 2008-12-15 23:53:10 +0000 | [diff] [blame] | 83 | |
| 84 | typedef void C2::f5(int); // expected-error{{typedef declarator cannot be qualified}} |
| 85 | |
| 86 | void f6(int A2::RC::x); // expected-error{{parameter declarator cannot be qualified}} |
| 87 | |
| 88 | int A2::RC::x; // expected-error{{non-static data member defined out-of-line}} |
| 89 | |
| 90 | void A2::CC::NC::m(); // expected-error{{out-of-line declaration of a member must be a definition}} |
Douglas Gregor | b6bf544 | 2008-12-16 06:37:47 +0000 | [diff] [blame] | 91 | |
| 92 | |
| 93 | namespace E { |
| 94 | int X = 5; |
| 95 | |
| 96 | namespace Nested { |
| 97 | enum E { |
| 98 | X = 0 |
| 99 | }; |
| 100 | |
| 101 | void f() { |
| 102 | return E::X; // expected-error{{expected a class or namespace}} |
| 103 | } |
| 104 | } |
| 105 | } |
Douglas Gregor | 853dd39 | 2008-12-26 15:00:45 +0000 | [diff] [blame^] | 106 | |
| 107 | |
| 108 | class Operators { |
| 109 | Operators operator+(const Operators&) const; // expected-note{{member declaration nearly matches}} |
| 110 | operator bool(); |
| 111 | }; |
| 112 | |
| 113 | Operators Operators::operator+(const Operators&) { // expected-error{{out-of-line definition does not match any declaration in 'Operators'}} |
| 114 | Operators ops; |
| 115 | return ops; |
| 116 | } |
| 117 | |
| 118 | Operators Operators::operator+(const Operators&) const { |
| 119 | Operators ops; |
| 120 | return ops; |
| 121 | } |
| 122 | |
| 123 | Operators::operator bool() { |
| 124 | return true; |
| 125 | } |