Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 2 | namespace Ns { |
| 3 | int f(); // expected-note{{previous declaration is here}} |
Douglas Gregor | 074149e | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 4 | |
| 5 | enum E { |
| 6 | Enumerator |
| 7 | }; |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 8 | } |
| 9 | namespace Ns { |
| 10 | double f(); // expected-error{{functions that differ only in their return type cannot be overloaded}} |
Douglas Gregor | 074149e | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 11 | |
| 12 | int x = Enumerator; |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 13 | } |
| 14 | |
| 15 | namespace Ns2 { |
| 16 | float f(); |
| 17 | } |
| 18 | |
Douglas Gregor | 074149e | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 19 | int y = Ns::Enumerator; |
| 20 | |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 21 | namespace Ns2 { |
| 22 | float f(int); // expected-note{{previous declaration is here}} |
| 23 | } |
| 24 | |
| 25 | namespace Ns2 { |
| 26 | double f(int); // expected-error{{functions that differ only in their return type cannot be overloaded}} |
| 27 | } |
| 28 | |
| 29 | namespace N { |
| 30 | int& f1(); |
| 31 | } |
| 32 | |
| 33 | namespace N { |
| 34 | struct f1 { |
| 35 | static int member; |
Douglas Gregor | 518fda1 | 2009-01-13 05:10:00 +0000 | [diff] [blame] | 36 | |
| 37 | typedef int type; |
| 38 | |
| 39 | void foo(type); |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 40 | }; |
| 41 | |
| 42 | void test_f1() { |
| 43 | int &i1 = f1(); |
| 44 | } |
| 45 | } |
| 46 | |
Douglas Gregor | 0b7a158 | 2009-01-17 00:42:38 +0000 | [diff] [blame] | 47 | void N::f1::foo(int i) { |
| 48 | f1::member = i; |
| 49 | f1::type &ir = i; |
| 50 | } |
Douglas Gregor | 518fda1 | 2009-01-13 05:10:00 +0000 | [diff] [blame] | 51 | |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 52 | namespace N { |
Douglas Gregor | 518fda1 | 2009-01-13 05:10:00 +0000 | [diff] [blame] | 53 | float& f1(int x) { |
| 54 | N::f1::type& i1 = x; |
Douglas Gregor | eb11cd0 | 2009-01-14 22:20:51 +0000 | [diff] [blame] | 55 | f1::type& i2 = x; |
Douglas Gregor | 518fda1 | 2009-01-13 05:10:00 +0000 | [diff] [blame] | 56 | } |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 57 | |
| 58 | struct f2 { |
| 59 | static int member; |
| 60 | }; |
| 61 | void f2(); |
| 62 | } |
| 63 | |
| 64 | int i1 = N::f1::member; |
| 65 | typedef struct N::f1 type1; |
| 66 | int i2 = N::f2::member; |
| 67 | typedef struct N::f2 type2; |
| 68 | |
| 69 | void test_f1(int i) { |
| 70 | int &v1 = N::f1(); |
| 71 | float &v2 = N::f1(i); |
Chris Lattner | a67865c | 2009-01-05 00:59:08 +0000 | [diff] [blame] | 72 | int v3 = ::i1; |
Douglas Gregor | 1a49af9 | 2009-01-06 05:10:23 +0000 | [diff] [blame] | 73 | int v4 = N::f1::member; |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 74 | } |
Chris Lattner | a67865c | 2009-01-05 00:59:08 +0000 | [diff] [blame] | 75 | |
Chris Lattner | 83cf05a | 2009-01-05 01:42:04 +0000 | [diff] [blame] | 76 | typedef int f2_type; |
| 77 | namespace a { |
| 78 | typedef int f2_type(int, int); |
| 79 | |
| 80 | void test_f2() { |
Douglas Gregor | 19311e7 | 2010-09-08 21:40:08 +0000 | [diff] [blame] | 81 | ::f2_type(1, 2); // expected-error {{excess elements in scalar initializer}} |
Chris Lattner | 83cf05a | 2009-01-05 01:42:04 +0000 | [diff] [blame] | 82 | } |
| 83 | } |
| 84 | |
Douglas Gregor | bc468ba | 2009-01-07 21:36:02 +0000 | [diff] [blame] | 85 | // PR clang/3291 |
| 86 | namespace a { |
| 87 | namespace a { // A1 |
| 88 | namespace a { // A2 |
Kaelyn Uhrain | 6e4f6f8 | 2013-10-19 00:04:52 +0000 | [diff] [blame] | 89 | int i; // expected-note{{'a::a::a::i' declared here}} |
Douglas Gregor | bc468ba | 2009-01-07 21:36:02 +0000 | [diff] [blame] | 90 | } |
| 91 | } |
| 92 | } |
Chris Lattner | 83cf05a | 2009-01-05 01:42:04 +0000 | [diff] [blame] | 93 | |
Douglas Gregor | bc468ba | 2009-01-07 21:36:02 +0000 | [diff] [blame] | 94 | void test_a() { |
Kaelyn Uhrain | 6e4f6f8 | 2013-10-19 00:04:52 +0000 | [diff] [blame] | 95 | a::a::i = 3; // expected-error{{no member named 'i' in namespace 'a::a'; did you mean 'a::a::a::i'?}} |
Douglas Gregor | bc468ba | 2009-01-07 21:36:02 +0000 | [diff] [blame] | 96 | a::a::a::i = 4; |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 97 | a::a::j = 3; // expected-error-re{{no member named 'j' in namespace 'a::a'{{$}}}} |
Douglas Gregor | bc468ba | 2009-01-07 21:36:02 +0000 | [diff] [blame] | 98 | } |
| 99 | |
John McCall | 7c2342d | 2010-03-10 11:27:22 +0000 | [diff] [blame] | 100 | struct Undef { // expected-note{{definition of 'Undef' is not complete until the closing '}'}} |
Douglas Gregor | 0b7a158 | 2009-01-17 00:42:38 +0000 | [diff] [blame] | 101 | typedef int type; |
| 102 | |
| 103 | Undef::type member; |
| 104 | |
John McCall | 7c2342d | 2010-03-10 11:27:22 +0000 | [diff] [blame] | 105 | static int size = sizeof(Undef); // expected-error{{invalid application of 'sizeof' to an incomplete type 'Undef'}} |
Douglas Gregor | 0b7a158 | 2009-01-17 00:42:38 +0000 | [diff] [blame] | 106 | |
| 107 | int f(); |
| 108 | }; |
| 109 | |
| 110 | int Undef::f() { |
| 111 | return sizeof(Undef); |
| 112 | } |
John McCall | 336e774 | 2009-12-02 19:59:55 +0000 | [diff] [blame] | 113 | |
| 114 | // PR clang/5667 |
| 115 | namespace test1 { |
| 116 | template <typename T> struct is_class { |
| 117 | enum { value = 0 }; |
| 118 | }; |
| 119 | |
| 120 | template <typename T> class ClassChecker { |
| 121 | bool isClass() { |
| 122 | return is_class<T>::value; |
| 123 | } |
| 124 | }; |
| 125 | |
| 126 | template class ClassChecker<int>; |
| 127 | } |
Douglas Gregor | 4074eef | 2010-04-23 02:08:13 +0000 | [diff] [blame] | 128 | |
| 129 | namespace PR6830 { |
| 130 | namespace foo { |
| 131 | |
| 132 | class X { |
| 133 | public: |
| 134 | X() {} |
| 135 | }; |
| 136 | |
| 137 | } // namespace foo |
| 138 | |
| 139 | class Z { |
| 140 | public: |
| 141 | explicit Z(const foo::X& x) {} |
| 142 | |
| 143 | void Work() {} |
| 144 | }; |
| 145 | |
| 146 | void Test() { |
| 147 | Z(foo::X()).Work(); |
| 148 | } |
| 149 | } |
Nick Lewycky | 173a37a | 2012-04-03 21:44:08 +0000 | [diff] [blame] | 150 | |
| 151 | namespace pr12339 { |
David Majnemer | aa71567 | 2013-05-29 00:56:45 +0000 | [diff] [blame] | 152 | extern "C" void i; // expected-error{{variable has incomplete type 'void'}} |
Nick Lewycky | 173a37a | 2012-04-03 21:44:08 +0000 | [diff] [blame] | 153 | pr12339::FOO // expected-error{{no type named 'FOO' in namespace 'pr12339'}} |
| 154 | } // expected-error{{expected unqualified-id}} |