Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 1 | // RUN: clang -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 | 518fda1 | 2009-01-13 05:10:00 +0000 | [diff] [blame^] | 47 | void N::f1::foo(int) { } |
| 48 | |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 49 | namespace N { |
Douglas Gregor | 518fda1 | 2009-01-13 05:10:00 +0000 | [diff] [blame^] | 50 | float& f1(int x) { |
| 51 | N::f1::type& i1 = x; |
| 52 | // FIXME: currently fails f1::type& i2 = x; |
| 53 | } |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 54 | |
| 55 | struct f2 { |
| 56 | static int member; |
| 57 | }; |
| 58 | void f2(); |
| 59 | } |
| 60 | |
| 61 | int i1 = N::f1::member; |
| 62 | typedef struct N::f1 type1; |
| 63 | int i2 = N::f2::member; |
| 64 | typedef struct N::f2 type2; |
| 65 | |
| 66 | void test_f1(int i) { |
| 67 | int &v1 = N::f1(); |
| 68 | float &v2 = N::f1(i); |
Chris Lattner | a67865c | 2009-01-05 00:59:08 +0000 | [diff] [blame] | 69 | int v3 = ::i1; |
Douglas Gregor | 1a49af9 | 2009-01-06 05:10:23 +0000 | [diff] [blame] | 70 | int v4 = N::f1::member; |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 71 | } |
Chris Lattner | a67865c | 2009-01-05 00:59:08 +0000 | [diff] [blame] | 72 | |
Chris Lattner | 83cf05a | 2009-01-05 01:42:04 +0000 | [diff] [blame] | 73 | typedef int f2_type; |
| 74 | namespace a { |
| 75 | typedef int f2_type(int, int); |
| 76 | |
| 77 | void test_f2() { |
| 78 | ::f2_type(1, 2); // expected-error {{function-style cast to a builtin type can only take one argument}} |
| 79 | } |
| 80 | } |
| 81 | |
Douglas Gregor | bc468ba | 2009-01-07 21:36:02 +0000 | [diff] [blame] | 82 | // PR clang/3291 |
| 83 | namespace a { |
| 84 | namespace a { // A1 |
| 85 | namespace a { // A2 |
| 86 | int i; |
| 87 | } |
| 88 | } |
| 89 | } |
Chris Lattner | 83cf05a | 2009-01-05 01:42:04 +0000 | [diff] [blame] | 90 | |
Douglas Gregor | bc468ba | 2009-01-07 21:36:02 +0000 | [diff] [blame] | 91 | void test_a() { |
| 92 | a::a::i = 3; // expected-error{{no member named 'i'}} |
| 93 | a::a::a::i = 4; |
| 94 | } |
| 95 | |
Chris Lattner | 83cf05a | 2009-01-05 01:42:04 +0000 | [diff] [blame] | 96 | |