Adrian Prantl | 4aa2b3a | 2015-09-08 19:20:27 +0000 | [diff] [blame] | 1 | /* -*- C++ -*- */ |
| 2 | namespace DebugCXX { |
| 3 | // Records. |
| 4 | struct Struct { |
| 5 | int i; |
| 6 | static int static_member; |
| 7 | }; |
| 8 | |
| 9 | // Enums. |
| 10 | enum Enum { |
| 11 | Enumerator |
| 12 | }; |
| 13 | enum { |
| 14 | e1 = '1' |
| 15 | }; |
| 16 | enum { |
| 17 | e2 = '2' |
| 18 | }; |
| 19 | |
Adrian Prantl | b2a8b35 | 2016-01-06 19:22:23 +0000 | [diff] [blame] | 20 | // Templates (instantiations). |
Adrian Prantl | 4aa2b3a | 2015-09-08 19:20:27 +0000 | [diff] [blame] | 21 | template<typename T> struct traits {}; |
| 22 | template<typename T, |
| 23 | typename Traits = traits<T> |
| 24 | > class Template { |
| 25 | T member; |
| 26 | }; |
Adrian Prantl | 05fefa4 | 2016-04-25 20:52:40 +0000 | [diff] [blame^] | 27 | // Explicit template instantiation. |
Adrian Prantl | 4aa2b3a | 2015-09-08 19:20:27 +0000 | [diff] [blame] | 28 | extern template class Template<int>; |
| 29 | |
| 30 | extern template struct traits<float>; |
Adrian Prantl | 05fefa4 | 2016-04-25 20:52:40 +0000 | [diff] [blame^] | 31 | typedef class Template<float> FloatInstantiation; |
Adrian Prantl | 4aa2b3a | 2015-09-08 19:20:27 +0000 | [diff] [blame] | 32 | |
| 33 | inline void fn() { |
| 34 | Template<long> invisible; |
| 35 | } |
| 36 | |
| 37 | // Non-template inside a template. |
| 38 | template <class> struct Outer { |
| 39 | Outer(); |
| 40 | struct Inner { |
| 41 | Inner(Outer) {} |
| 42 | }; |
| 43 | }; |
| 44 | template <class T> Outer<T>::Outer() { |
| 45 | Inner a(*this); |
| 46 | }; |
| 47 | |
| 48 | // Partial template specialization. |
| 49 | template <typename...> class A; |
| 50 | template <typename T> class A<T> {}; |
| 51 | typedef A<void> B; |
Adrian Prantl | 05fefa4 | 2016-04-25 20:52:40 +0000 | [diff] [blame^] | 52 | // Anchored by a function parameter. |
Adrian Prantl | 4aa2b3a | 2015-09-08 19:20:27 +0000 | [diff] [blame] | 53 | void foo(B) {} |
| 54 | } |
Adrian Prantl | b3b821f | 2016-01-06 19:22:19 +0000 | [diff] [blame] | 55 | |
| 56 | // Virtual class with a forward declaration. |
| 57 | class FwdVirtual; |
| 58 | class FwdVirtual { |
| 59 | virtual ~FwdVirtual() {} |
| 60 | }; |
Adrian Prantl | 35e765b | 2016-01-09 01:11:35 +0000 | [diff] [blame] | 61 | |
| 62 | struct PureForwardDecl; |
Adrian Prantl | e5238d2 | 2016-01-19 18:02:47 +0000 | [diff] [blame] | 63 | |
| 64 | typedef union { int i; } TypedefUnion; |
| 65 | typedef enum { e0 = 0 } TypedefEnum; |
| 66 | typedef struct { int i; } TypedefStruct; |
Adrian Prantl | cd97501 | 2016-01-19 23:42:44 +0000 | [diff] [blame] | 67 | |
| 68 | union { int i; } GlobalUnion; |
| 69 | struct { int i; } GlobalStruct; |
| 70 | enum { e5 = 5 } GlobalEnum; |
Adrian Prantl | 8f55b66 | 2016-01-20 01:29:34 +0000 | [diff] [blame] | 71 | |
| 72 | namespace { |
| 73 | namespace { |
| 74 | struct InAnonymousNamespace { int i; }; |
| 75 | } |
| 76 | } |
Adrian Prantl | 5a9a427 | 2016-03-07 20:58:52 +0000 | [diff] [blame] | 77 | |
| 78 | class Base; |
| 79 | class A { |
| 80 | virtual Base *getParent() const; |
| 81 | }; |
| 82 | class Base {}; |
| 83 | class Derived : Base { |
| 84 | class B : A { |
| 85 | Derived *getParent() const override; |
| 86 | }; |
| 87 | }; |
Adrian Prantl | 05fefa4 | 2016-04-25 20:52:40 +0000 | [diff] [blame^] | 88 | |
| 89 | template <class T> |
| 90 | class Template1 { |
| 91 | T t; |
| 92 | }; |
| 93 | typedef Template1<void *> TypedefTemplate; |
| 94 | extern template class Template1<int>; |
| 95 | |
| 96 | template <class T> class FwdDeclTemplate; |
| 97 | typedef FwdDeclTemplate<int> TypedefFwdDeclTemplate; |