Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
Douglas Gregor | 2bba76b | 2009-05-27 17:07:49 +0000 | [diff] [blame] | 2 | namespace N { |
| 3 | struct Outer { |
| 4 | struct Inner { |
| 5 | template<typename T> |
| 6 | struct InnerTemplate { |
| 7 | struct VeryInner { |
| 8 | typedef T type; |
| 9 | |
| 10 | static enum K1 { K1Val = sizeof(T) } Kind1; |
Douglas Gregor | 8dbc3c6 | 2009-05-27 17:20:35 +0000 | [diff] [blame] | 11 | static enum { K2Val = sizeof(T)*2 } Kind2; |
Douglas Gregor | d0c8737 | 2009-05-27 17:30:49 +0000 | [diff] [blame] | 12 | enum { K3Val = sizeof(T)*2 } Kind3; |
Douglas Gregor | 2bba76b | 2009-05-27 17:07:49 +0000 | [diff] [blame] | 13 | |
| 14 | void foo() { |
| 15 | K1 k1 = K1Val; |
| 16 | Kind1 = K1Val; |
| 17 | Outer::Inner::InnerTemplate<type>::VeryInner::Kind2 = K2Val; |
Douglas Gregor | d0c8737 | 2009-05-27 17:30:49 +0000 | [diff] [blame] | 18 | Kind3 = K3Val; |
Douglas Gregor | 2bba76b | 2009-05-27 17:07:49 +0000 | [diff] [blame] | 19 | } |
Douglas Gregor | d0c8737 | 2009-05-27 17:30:49 +0000 | [diff] [blame] | 20 | |
| 21 | struct UeberInner { |
| 22 | void bar() { |
| 23 | K1 k1 = K1Val; |
| 24 | Kind1 = K1Val; |
| 25 | Outer::Inner::InnerTemplate<type>::VeryInner::Kind2 = K2Val; |
Douglas Gregor | ed961e7 | 2009-05-27 17:54:46 +0000 | [diff] [blame] | 26 | |
| 27 | InnerTemplate t; |
| 28 | InnerTemplate<type> t2; |
Douglas Gregor | d0c8737 | 2009-05-27 17:30:49 +0000 | [diff] [blame] | 29 | } |
| 30 | }; |
Douglas Gregor | 2bba76b | 2009-05-27 17:07:49 +0000 | [diff] [blame] | 31 | }; |
| 32 | }; |
| 33 | }; |
| 34 | }; |
| 35 | } |
| 36 | |
| 37 | typedef int INT; |
| 38 | template struct N::Outer::Inner::InnerTemplate<INT>::VeryInner; |
Douglas Gregor | 1eabb7d | 2010-03-31 23:17:41 +0000 | [diff] [blame] | 39 | template struct N::Outer::Inner::InnerTemplate<INT>::UeberInner; // expected-error{{no struct named 'UeberInner' in 'N::Outer::Inner::InnerTemplate<int>'}} |
Douglas Gregor | 6569d68 | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 40 | |
| 41 | namespace N2 { |
| 42 | struct Outer2 { |
Douglas Gregor | 8e92bf3 | 2009-05-29 14:25:00 +0000 | [diff] [blame] | 43 | template<typename T, typename U = T> |
Douglas Gregor | 6569d68 | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 44 | struct Inner { |
| 45 | void foo() { |
| 46 | enum { K1Val = sizeof(T) } k1; |
Douglas Gregor | 8e92bf3 | 2009-05-29 14:25:00 +0000 | [diff] [blame] | 47 | enum K2 { K2Val = sizeof(T)*2 } k2a; |
Douglas Gregor | 6569d68 | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 48 | |
Douglas Gregor | 8e92bf3 | 2009-05-29 14:25:00 +0000 | [diff] [blame] | 49 | K2 k2b = K2Val; |
| 50 | |
| 51 | struct S { T x, y; } s1; |
| 52 | struct { U x, y; } s2; |
| 53 | s1.x = s2.x; // expected-error{{incompatible}} |
| 54 | |
| 55 | typedef T type; |
| 56 | type t2 = s1.x; |
Douglas Gregor | 6569d68 | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 57 | |
Douglas Gregor | 7b0a572 | 2009-05-29 14:26:40 +0000 | [diff] [blame] | 58 | typedef struct { T z; } type2; |
| 59 | type2 t3 = { s1.x }; |
| 60 | |
Douglas Gregor | 6569d68 | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 61 | Inner i1; |
| 62 | i1.foo(); |
| 63 | Inner<T> i2; |
| 64 | i2.foo(); |
| 65 | } |
| 66 | }; |
| 67 | }; |
| 68 | } |
| 69 | |
Douglas Gregor | 8e92bf3 | 2009-05-29 14:25:00 +0000 | [diff] [blame] | 70 | template struct N2::Outer2::Inner<float>; |
| 71 | template struct N2::Outer2::Inner<int*, float*>; // expected-note{{instantiation}} |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 72 | |
| 73 | // Test dependent pointer-to-member expressions. |
| 74 | template<typename T> |
| 75 | struct smart_ptr { |
| 76 | struct safe_bool { |
| 77 | int member; |
| 78 | }; |
| 79 | |
| 80 | operator int safe_bool::*() const { |
| 81 | return ptr? &safe_bool::member : 0; |
| 82 | } |
| 83 | |
| 84 | T* ptr; |
| 85 | }; |
| 86 | |
| 87 | void test_smart_ptr(smart_ptr<int> p) { |
| 88 | if (p) { } |
| 89 | } |
John McCall | 68b6b87 | 2010-02-06 01:50:47 +0000 | [diff] [blame] | 90 | |
| 91 | // PR5517 |
| 92 | namespace test0 { |
| 93 | template <int K> struct X { |
| 94 | X() { extern void x(); } |
| 95 | }; |
| 96 | void g() { X<2>(); } |
| 97 | } |
John McCall | ec8045d | 2010-08-17 21:27:17 +0000 | [diff] [blame] | 98 | |
| 99 | // <rdar://problem/8302161> |
| 100 | namespace test1 { |
| 101 | template <typename T> void f(T const &t) { |
| 102 | union { char c; T t_; }; |
| 103 | c = 'a'; // <- this shouldn't silently fail to instantiate |
| 104 | T::foo(); // expected-error {{has no members}} |
| 105 | } |
| 106 | template void f(int const &); // expected-note {{requested here}} |
| 107 | } |