reference, declarationdefinition
definition → references, declarations, derived classes, virtual overrides
reference to multiple definitions → definitions
unreferenced
    1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86
   87
   88
   89
   90
   91
   92
   93
   94
   95
   96
   97
   98
   99
  100
  101
  102
  103
  104
  105
  106
  107
  108
  109
  110
  111
  112
  113
  114
  115
  116
  117
  118
  119
  120
  121
  122
  123
  124
  125
  126
  127
  128
  129
  130
  131
  132
  133
  134
  135
  136
  137
  138
  139
  140
  141
  142
  143
  144
  145
  146
  147
  148
  149
  150
  151
  152
  153
  154
  155
  156
  157
  158
  159
  160
  161
  162
  163
  164
  165
  166
  167
  168
  169
  170
  171
  172
  173
  174
  175
  176
  177
  178
  179
  180
  181
  182
  183
  184
  185
  186
  187
  188
  189
  190
  191
  192
  193
  194
  195
  196
  197
  198
  199
  200
  201
  202
  203
  204
  205
  206
  207
  208
  209
  210
  211
  212
  213
  214
  215
  216
  217
  218
  219
  220
  221
  222
  223
  224
  225
  226
  227
  228
  229
  230
  231
  232
  233
  234
  235
  236
  237
  238
  239
  240
  241
  242
  243
  244
  245
  246
  247
  248
  249
  250
  251
  252
  253
  254
  255
  256
  257
  258
  259
  260
  261
  262
  263
  264
  265
  266
  267
  268
  269
  270
  271
  272
  273
  274
  275
  276
  277
  278
  279
  280
  281
  282
  283
  284
  285
  286
  287
  288
  289
  290
  291
  292
  293
  294
  295
  296
  297
  298
  299
  300
  301
  302
  303
  304
  305
  306
  307
  308
  309
  310
  311
  312
// RUN: %clang_cc1 -std=c++11 -fms-compatibility-version=19 -emit-llvm %s -o - -fms-extensions -fdelayed-template-parsing -triple=i386-pc-win32 | FileCheck %s
// RUN: %clang_cc1 -std=c++11 -fms-compatibility-version=19 -emit-llvm %s -o - -fms-extensions -fdelayed-template-parsing -triple=x86_64-pc-win32 | FileCheck -check-prefix X64 %s
// RUN: %clang_cc1 -std=c++17 -fms-compatibility-version=19 -emit-llvm %s -o - -fms-extensions -fdelayed-template-parsing -triple=i386-pc-win32 | FileCheck %s
// RUN: %clang_cc1 -std=c++17 -fms-compatibility-version=19 -emit-llvm %s -o - -fms-extensions -fdelayed-template-parsing -triple=x86_64-pc-win32 | FileCheck -check-prefix X64 %s

template<typename T>
class Class {
 public:
  Class() {}
};

class Typename { };

template<typename T>
class Nested { };

template<bool flag>
class BoolTemplate {
 public:
  BoolTemplate() {}
};

template<int param>
class IntTemplate {
 public:
  IntTemplate() {}
};

template<unsigned param>
class UnsignedIntTemplate {
public:
  UnsignedIntTemplate() {}
};

template<long long param>
class LongLongTemplate {
 public:
  LongLongTemplate() {}
};

template<unsigned long long param>
class UnsignedLongLongTemplate {
 public:
  UnsignedLongLongTemplate() {}
};

template<>
class BoolTemplate<true> {
 public:
  BoolTemplate() {}
  template<class T> void Foo(T arg) {}
};

void template_mangling() {
  Class<Typename> c1;
// CHECK: call {{.*}} @"??0?$Class@VTypename@@@@QAE@XZ"
// X64: call {{.*}} @"??0?$Class@VTypename@@@@QEAA@XZ"

  Class<const Typename> c1_const;
// CHECK: call {{.*}} @"??0?$Class@$$CBVTypename@@@@QAE@XZ"
// X64: call {{.*}} @"??0?$Class@$$CBVTypename@@@@QEAA@XZ"
  Class<volatile Typename> c1_volatile;
// CHECK: call {{.*}} @"??0?$Class@$$CCVTypename@@@@QAE@XZ"
// X64: call {{.*}} @"??0?$Class@$$CCVTypename@@@@QEAA@XZ"
  Class<const volatile Typename> c1_cv;
// CHECK: call {{.*}} @"??0?$Class@$$CDVTypename@@@@QAE@XZ"
// X64: call {{.*}} @"??0?$Class@$$CDVTypename@@@@QEAA@XZ"

  Class<Nested<Typename> > c2;
// CHECK: call {{.*}} @"??0?$Class@V?$Nested@VTypename@@@@@@QAE@XZ"
// X64: call {{.*}} @"??0?$Class@V?$Nested@VTypename@@@@@@QEAA@XZ"

  Class<int * const> c_intpc;
// CHECK: call {{.*}} @"??0?$Class@QAH@@QAE@XZ"
// X64: call {{.*}} @"??0?$Class@QEAH@@QEAA@XZ"
  Class<int()> c_ft;
// CHECK: call {{.*}} @"??0?$Class@$$A6AHXZ@@QAE@XZ"
// X64: call {{.*}} @"??0?$Class@$$A6AHXZ@@QEAA@XZ"
  Class<int[]> c_inti;
// CHECK: call {{.*}} @"??0?$Class@$$BY0A@H@@QAE@XZ"
// X64: call {{.*}} @"??0?$Class@$$BY0A@H@@QEAA@XZ"
  Class<int[5]> c_int5;
// CHECK: call {{.*}} @"??0?$Class@$$BY04H@@QAE@XZ"
// X64: call {{.*}} @"??0?$Class@$$BY04H@@QEAA@XZ"
  Class<const int[5]> c_intc5;
// CHECK: call {{.*}} @"??0?$Class@$$BY04$$CBH@@QAE@XZ"
// X64: call {{.*}} @"??0?$Class@$$BY04$$CBH@@QEAA@XZ"
  Class<int * const[5]> c_intpc5;
// CHECK: call {{.*}} @"??0?$Class@$$BY04QAH@@QAE@XZ"
// X64: call {{.*}} @"??0?$Class@$$BY04QEAH@@QEAA@XZ"

  BoolTemplate<false> _false;
// CHECK: call {{.*}} @"??0?$BoolTemplate@$0A@@@QAE@XZ"
// X64: call {{.*}} @"??0?$BoolTemplate@$0A@@@QEAA@XZ"

  BoolTemplate<true> _true;
  // PR13158
  _true.Foo(1);
// CHECK: call {{.*}} @"??0?$BoolTemplate@$00@@QAE@XZ"
// X64: call {{.*}} @"??0?$BoolTemplate@$00@@QEAA@XZ"
// CHECK: call {{.*}} @"??$Foo@H@?$BoolTemplate@$00@@QAEXH@Z"
// X64: call {{.*}} @"??$Foo@H@?$BoolTemplate@$00@@QEAAXH@Z"

  IntTemplate<0> zero;
// CHECK: call {{.*}} @"??0?$IntTemplate@$0A@@@QAE@XZ"
// X64: call {{.*}} @"??0?$IntTemplate@$0A@@@QEAA@XZ"

  IntTemplate<5> five;
// CHECK: call {{.*}} @"??0?$IntTemplate@$04@@QAE@XZ"
// X64: call {{.*}} @"??0?$IntTemplate@$04@@QEAA@XZ"

  IntTemplate<11> eleven;
// CHECK: call {{.*}} @"??0?$IntTemplate@$0L@@@QAE@XZ"
// X64: call {{.*}} @"??0?$IntTemplate@$0L@@@QEAA@XZ"

  IntTemplate<256> _256;
// CHECK: call {{.*}} @"??0?$IntTemplate@$0BAA@@@QAE@XZ"
// X64: call {{.*}} @"??0?$IntTemplate@$0BAA@@@QEAA@XZ"

  IntTemplate<513> _513;
// CHECK: call {{.*}} @"??0?$IntTemplate@$0CAB@@@QAE@XZ"
// X64: call {{.*}} @"??0?$IntTemplate@$0CAB@@@QEAA@XZ"

  IntTemplate<1026> _1026;
// CHECK: call {{.*}} @"??0?$IntTemplate@$0EAC@@@QAE@XZ"
// X64: call {{.*}} @"??0?$IntTemplate@$0EAC@@@QEAA@XZ"

  IntTemplate<65535> ffff;
// CHECK: call {{.*}} @"??0?$IntTemplate@$0PPPP@@@QAE@XZ"
// X64: call {{.*}} @"??0?$IntTemplate@$0PPPP@@@QEAA@XZ"

  IntTemplate<-1>  neg_1;
// CHECK: call {{.*}} @"??0?$IntTemplate@$0?0@@QAE@XZ"
// X64: call {{.*}} @"??0?$IntTemplate@$0?0@@QEAA@XZ"
  IntTemplate<-9>  neg_9;
// CHECK: call {{.*}} @"??0?$IntTemplate@$0?8@@QAE@XZ"
// X64: call {{.*}} @"??0?$IntTemplate@$0?8@@QEAA@XZ"
  IntTemplate<-10> neg_10;
// CHECK: call {{.*}} @"??0?$IntTemplate@$0?9@@QAE@XZ"
// X64: call {{.*}} @"??0?$IntTemplate@$0?9@@QEAA@XZ"
  IntTemplate<-11> neg_11;
// CHECK: call {{.*}} @"??0?$IntTemplate@$0?L@@@QAE@XZ"
// X64: call {{.*}} @"??0?$IntTemplate@$0?L@@@QEAA@XZ"
  
  UnsignedIntTemplate<4294967295> ffffffff;
// CHECK: call {{.*}} @"??0?$UnsignedIntTemplate@$0PPPPPPPP@@@QAE@XZ"
// X64: call {{.*}} @"??0?$UnsignedIntTemplate@$0PPPPPPPP@@@QEAA@XZ"

  LongLongTemplate<-9223372036854775807LL-1LL> int64_min;
// CHECK: call {{.*}} @"??0?$LongLongTemplate@$0?IAAAAAAAAAAAAAAA@@@QAE@XZ"
// X64: call {{.*}} @"??0?$LongLongTemplate@$0?IAAAAAAAAAAAAAAA@@@QEAA@XZ"
  LongLongTemplate<9223372036854775807LL>      int64_max;
// CHECK: call {{.*}} @"??0?$LongLongTemplate@$0HPPPPPPPPPPPPPPP@@@QAE@XZ"
// X64: call {{.*}} @"??0?$LongLongTemplate@$0HPPPPPPPPPPPPPPP@@@QEAA@XZ"
  UnsignedLongLongTemplate<18446744073709551615ULL> uint64_max;
// CHECK: call {{.*}} @"??0?$UnsignedLongLongTemplate@$0?0@@QAE@XZ"
// X64: call {{.*}} @"??0?$UnsignedLongLongTemplate@$0?0@@QEAA@XZ"
  UnsignedLongLongTemplate<(unsigned long long)-1>  uint64_neg_1;
// CHECK: call {{.*}} @"??0?$UnsignedLongLongTemplate@$0?0@@QAE@XZ"
// X64: call {{.*}} @"??0?$UnsignedLongLongTemplate@$0?0@@QEAA@XZ"
}

namespace space {
  template<class T> const T& foo(const T& l) { return l; }
}
// CHECK: "??$foo@H@space@@YAABHABH@Z"
// X64: "??$foo@H@space@@YAAEBHAEBH@Z"

void use() {
  space::foo(42);
}

// PR13455
typedef void (*FunctionPointer)(void);

template <FunctionPointer function>
void FunctionPointerTemplate() {
  function();
}

void spam() {
  FunctionPointerTemplate<spam>();
// CHECK: "??$FunctionPointerTemplate@$1?spam@@YAXXZ@@YAXXZ"
// X64: "??$FunctionPointerTemplate@$1?spam@@YAXXZ@@YAXXZ"
}

// Unlike Itanium, there is no character code to indicate an argument pack.
// Tested with MSVC 2013, the first version which supports variadic templates.

template <typename ...Ts> void variadic_fn_template(const Ts &...args);
template <typename... Ts, typename... Us>
void multi_variadic_fn(Ts... ts, Us... us);
template <typename... Ts, typename C, typename... Us>
void multi_variadic_mixed(Ts... ts, C c, Us... us);
void variadic_fn_instantiate() {
  variadic_fn_template(0, 1, 3, 4);
  variadic_fn_template(0, 1, 'a', "b");

  // Directlly consecutive packs are separated by $$Z...
  multi_variadic_fn<int, int>(1, 2, 3, 4, 5);
  multi_variadic_fn<int, int, int>(1, 2, 3, 4, 5);

  // ...but not if another template parameter is between them.
  multi_variadic_mixed<int, int>(1, 2, 3);
  multi_variadic_mixed<int, int>(1, 2, 3, 4);
}
// CHECK: "??$variadic_fn_template@HHHH@@YAXABH000@Z"
// X64:   "??$variadic_fn_template@HHHH@@YAXAEBH000@Z"
// CHECK: "??$variadic_fn_template@HHD$$BY01D@@YAXABH0ABDAAY01$$CBD@Z"
// X64:   "??$variadic_fn_template@HHD$$BY01D@@YAXAEBH0AEBDAEAY01$$CBD@Z"
// CHECK: "??$multi_variadic_fn@HH$$ZHHH@@YAXHHHHH@Z"
// X64:   "??$multi_variadic_fn@HH$$ZHHH@@YAXHHHHH@Z"
// CHECK: "??$multi_variadic_fn@HHH$$ZHH@@YAXHHHHH@Z"
// X64:   "??$multi_variadic_fn@HHH$$ZHH@@YAXHHHHH@Z"
// CHECK: "??$multi_variadic_mixed@HHH$$V@@YAXHHH@Z"
// X64:   "??$multi_variadic_mixed@HHH$$V@@YAXHHH@Z"
// CHECK: "??$multi_variadic_mixed@HHHH@@YAXHHHH@Z"
// X64:   "??$multi_variadic_mixed@HHHH@@YAXHHHH@Z"

template <typename ...Ts>
struct VariadicClass {
  VariadicClass() { }
  int x;
};
void variadic_class_instantiate() {
  VariadicClass<int, char, bool> a;
  VariadicClass<bool, char, int> b;
}
// CHECK: call {{.*}} @"??0?$VariadicClass@HD_N@@QAE@XZ"
// CHECK: call {{.*}} @"??0?$VariadicClass@_NDH@@QAE@XZ"

template <typename T>
struct Second {};

template <typename T, template <class> class>
struct Type {};

template <template <class> class T>
struct Type2 {};

template <template <class> class T, bool B>
struct Thing;

template <template <class> class T>
struct Thing<T, false> { };

template <template <class> class T>
struct Thing<T, true> { };

void template_template_fun(Type<Thing<Second, true>, Second>) { }
// CHECK: "?template_template_fun@@YAXU?$Type@U?$Thing@USecond@@$00@@USecond@@@@@Z"

template <typename T>
void template_template_specialization();

template <>
void template_template_specialization<void (Type<Thing<Second, true>, Second>)>() {
}
// CHECK: "??$template_template_specialization@$$A6AXU?$Type@U?$Thing@USecond@@$00@@USecond@@@@@Z@@YAXXZ"

// PR16788
template <decltype(nullptr)> struct S1 {};
void f(S1<nullptr>) {}
// CHECK: "?f@@YAXU?$S1@$0A@@@@Z"

struct record {
  int first;
  int second;
};
template <const record &>
struct type1 {
};
extern const record inst;
void recref(type1<inst>) {}
// CHECK: "?recref@@YAXU?$type1@$E?inst@@3Urecord@@B@@@Z"

struct _GUID {};
struct __declspec(uuid("{12345678-1234-1234-1234-1234567890aB}")) uuid;

template <typename T, const _GUID *G = &__uuidof(T)>
struct UUIDType1 {};

template <typename T, const _GUID &G = __uuidof(T)>
struct UUIDType2 {};

void fun(UUIDType1<uuid> a) {}
// CHECK: "?fun@@YAXU?$UUIDType1@Uuuid@@$1?_GUID_12345678_1234_1234_1234_1234567890ab@@3U__s_GUID@@B@@@Z"
void fun(UUIDType2<uuid> b) {}
// CHECK: "?fun@@YAXU?$UUIDType2@Uuuid@@$E?_GUID_12345678_1234_1234_1234_1234567890ab@@3U__s_GUID@@B@@@Z"

template <typename T> struct TypeWithFriendDefinition {
  friend void FunctionDefinedWithInjectedName(TypeWithFriendDefinition<T>) {}
};
// CHECK: call {{.*}} @"?FunctionDefinedWithInjectedName@@YAXU?$TypeWithFriendDefinition@H@@@Z"
void CallFunctionDefinedWithInjectedName() {
  FunctionDefinedWithInjectedName(TypeWithFriendDefinition<int>());
}
// CHECK: @"?FunctionDefinedWithInjectedName@@YAXU?$TypeWithFriendDefinition@H@@@Z"

// We need to be able to feed GUIDs through a couple rounds of template
// substitution.
template <const _GUID *G>
struct UUIDType3 {
  void foo() {}
};
template <const _GUID *G>
struct UUIDType4 : UUIDType3<G> {
  void bar() { UUIDType4::foo(); }
};
template struct UUIDType4<&__uuidof(uuid)>;
// CHECK: "?bar@?$UUIDType4@$1?_GUID_12345678_1234_1234_1234_1234567890ab@@3U__s_GUID@@B@@QAEXXZ"
// CHECK: "?foo@?$UUIDType3@$1?_GUID_12345678_1234_1234_1234_1234567890ab@@3U__s_GUID@@B@@QAEXXZ"