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