| Douglas Gregor | 8acb727 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 1 | // RUN: clang -fsyntax-only -verify %s |
| Douglas Gregor | 8acb727 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 2 | namespace Ns { |
| 3 | int f(); // expected-note{{previous declaration is here}} |
| Douglas Gregor | d802838 | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 4 | |
| 5 | enum E { |
| 6 | Enumerator |
| 7 | }; |
| Douglas Gregor | 8acb727 | 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 | d802838 | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 11 | |
| 12 | int x = Enumerator; |
| Douglas Gregor | 8acb727 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 13 | } |
| 14 | |
| 15 | namespace Ns2 { |
| 16 | float f(); |
| 17 | } |
| 18 | |
| Douglas Gregor | d802838 | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 19 | int y = Ns::Enumerator; |
| 20 | |
| Douglas Gregor | 8acb727 | 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; |
| 36 | }; |
| 37 | |
| 38 | void test_f1() { |
| 39 | int &i1 = f1(); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | namespace N { |
| 44 | float& f1(int); |
| 45 | |
| 46 | struct f2 { |
| 47 | static int member; |
| 48 | }; |
| 49 | void f2(); |
| 50 | } |
| 51 | |
| 52 | int i1 = N::f1::member; |
| 53 | typedef struct N::f1 type1; |
| 54 | int i2 = N::f2::member; |
| 55 | typedef struct N::f2 type2; |
| 56 | |
| 57 | void test_f1(int i) { |
| 58 | int &v1 = N::f1(); |
| 59 | float &v2 = N::f1(i); |
| Chris Lattner | 7d9d413 | 2009-01-05 00:59:08 +0000 | [diff] [blame] | 60 | int v3 = ::i1; |
| Douglas Gregor | 566782a | 2009-01-06 05:10:23 +0000 | [diff] [blame] | 61 | int v4 = N::f1::member; |
| Douglas Gregor | 8acb727 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 62 | } |
| Chris Lattner | 7d9d413 | 2009-01-05 00:59:08 +0000 | [diff] [blame] | 63 | |
| Chris Lattner | 4899a75 | 2009-01-05 01:42:04 +0000 | [diff] [blame] | 64 | typedef int f2_type; |
| 65 | namespace a { |
| 66 | typedef int f2_type(int, int); |
| 67 | |
| 68 | void test_f2() { |
| 69 | ::f2_type(1, 2); // expected-error {{function-style cast to a builtin type can only take one argument}} |
| 70 | } |
| 71 | } |
| 72 | |
| Douglas Gregor | 1ae2770 | 2009-01-07 21:36:02 +0000 | [diff] [blame^] | 73 | // PR clang/3291 |
| 74 | namespace a { |
| 75 | namespace a { // A1 |
| 76 | namespace a { // A2 |
| 77 | int i; |
| 78 | } |
| 79 | } |
| 80 | } |
| Chris Lattner | 4899a75 | 2009-01-05 01:42:04 +0000 | [diff] [blame] | 81 | |
| Douglas Gregor | 1ae2770 | 2009-01-07 21:36:02 +0000 | [diff] [blame^] | 82 | void test_a() { |
| 83 | a::a::i = 3; // expected-error{{no member named 'i'}} |
| 84 | a::a::a::i = 4; |
| 85 | } |
| 86 | |
| Chris Lattner | 4899a75 | 2009-01-05 01:42:04 +0000 | [diff] [blame] | 87 | |