[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / CodeGenCXX / predefined-expr.cpp
blobe6bf4297eb7af5c7ac018a70fe9f03f8608c9303
1 // RUN: %clang_cc1 -std=c++11 -fblocks %s -triple %itanium_abi_triple -emit-llvm -o - | FileCheck %s
3 // CHECK-DAG: private unnamed_addr constant [15 x i8] c"externFunction\00"
4 // CHECK-DAG: private unnamed_addr constant [26 x i8] c"void NS::externFunction()\00"
5 // CHECK-DAG: private unnamed_addr constant [49 x i8] c"void functionTemplateExplicitSpecialization(int)\00"
7 // CHECK-DAG: private unnamed_addr constant [95 x i8] c"void SpecializedClassTemplate<char>::memberFunctionTemplate(T, U) const [T = char, U = double]\00"
8 // CHECK-DAG: private unnamed_addr constant [85 x i8] c"void SpecializedClassTemplate<int>::memberFunctionTemplate(int, U) const [U = float]\00"
9 // CHECK-DAG: private unnamed_addr constant [57 x i8] c"void NonTypeTemplateParam<42>::size() const [Count = 42]\00"
10 // CHECK-DAG: private unnamed_addr constant [103 x i8] c"static void ClassWithTemplateTemplateParam<char>::staticMember() [T = char, Param = NS::ClassTemplate]\00"
11 // CHECK-DAG: private unnamed_addr constant [106 x i8] c"void OuterClass<int *>::MiddleClass::InnerClass<float>::memberFunction(T, U) const [T = int *, U = float]\00"
12 // CHECK-DAG: private unnamed_addr constant [51 x i8] c"void functionTemplateWithCapturedStmt(T) [T = int]\00"
13 // CHECK-DAG: private unnamed_addr constant [76 x i8] c"auto functionTemplateWithLambda(int)::(anonymous class)::operator()() const\00"
14 // CHECK-DAG: private unnamed_addr constant [65 x i8] c"void functionTemplateWithUnnamedTemplateParameter(T) [T = float]\00"
16 // CHECK-DAG: private unnamed_addr constant [60 x i8] c"void functionTemplateExplicitSpecialization(T) [T = double]\00"
17 // CHECK-DAG: private unnamed_addr constant [52 x i8] c"T *functionTemplateWithCompoundTypes(T *) [T = int]\00"
18 // CHECK-DAG: private unnamed_addr constant [54 x i8] c"T functionTemplateWithTemplateReturnType() [T = char]\00"
19 // CHECK-DAG: private unnamed_addr constant [57 x i8] c"void functionTemplateWithoutParameterList() [T = double]\00"
20 // CHECK-DAG: private unnamed_addr constant [62 x i8] c"void functionTemplateWithTwoParams(T, U) [T = int, U = float]\00"
22 // CHECK-DAG: private unnamed_addr constant [22 x i8] c"classTemplateFunction\00"
23 // CHECK-DAG: private unnamed_addr constant [77 x i8] c"void NS::ClassTemplate<NS::Base *>::classTemplateFunction() [T = NS::Base *]\00"
24 // CHECK-DAG: private unnamed_addr constant [63 x i8] c"void NS::ClassTemplate<int>::classTemplateFunction() [T = int]\00"
26 // CHECK-DAG: private unnamed_addr constant [18 x i8] c"functionTemplate1\00"
27 // CHECK-DAG: private unnamed_addr constant [53 x i8] c"void NS::Base::functionTemplate1(T) [T = NS::Base *]\00"
28 // CHECK-DAG: private unnamed_addr constant [46 x i8] c"void NS::Base::functionTemplate1(T) [T = int]\00"
30 // CHECK-DAG: private unnamed_addr constant [23 x i8] c"anonymousUnionFunction\00"
31 // CHECK-DAG: private unnamed_addr constant [83 x i8] c"void NS::ContainerForAnonymousRecords::(anonymous union)::anonymousUnionFunction()\00"
33 // CHECK-DAG: private unnamed_addr constant [24 x i8] c"anonymousStructFunction\00"
34 // CHECK-DAG: private unnamed_addr constant [85 x i8] c"void NS::ContainerForAnonymousRecords::(anonymous struct)::anonymousStructFunction()\00"
36 // CHECK-DAG: private unnamed_addr constant [23 x i8] c"anonymousClassFunction\00"
37 // CHECK-DAG: private unnamed_addr constant [83 x i8] c"void NS::ContainerForAnonymousRecords::(anonymous class)::anonymousClassFunction()\00"
39 // CHECK-DAG: private unnamed_addr constant [12 x i8] c"~Destructor\00"
40 // CHECK-DAG: private unnamed_addr constant [30 x i8] c"NS::Destructor::~Destructor()\00"
42 // CHECK-DAG: private unnamed_addr constant [12 x i8] c"Constructor\00"
43 // CHECK-DAG: private unnamed_addr constant [37 x i8] c"NS::Constructor::Constructor(Base *)\00"
44 // CHECK-DAG: private unnamed_addr constant [34 x i8] c"NS::Constructor::Constructor(int)\00"
45 // CHECK-DAG: private unnamed_addr constant [31 x i8] c"NS::Constructor::Constructor()\00"
47 // CHECK-DAG: private unnamed_addr constant [16 x i8] c"virtualFunction\00"
48 // CHECK-DAG: private unnamed_addr constant [44 x i8] c"virtual void NS::Derived::virtualFunction()\00"
50 // CHECK-DAG: private unnamed_addr constant [21 x i8] c"refQualifiedFunction\00"
51 // CHECK-DAG: private unnamed_addr constant [41 x i8] c"void NS::Base::refQualifiedFunction() &&\00"
52 // CHECK-DAG: private unnamed_addr constant [40 x i8] c"void NS::Base::refQualifiedFunction() &\00"
54 // CHECK-DAG: private unnamed_addr constant [22 x i8] c"constVolatileFunction\00"
55 // CHECK-DAG: private unnamed_addr constant [54 x i8] c"void NS::Base::constVolatileFunction() const volatile\00"
57 // CHECK-DAG: private unnamed_addr constant [17 x i8] c"volatileFunction\00"
58 // CHECK-DAG: private unnamed_addr constant [43 x i8] c"void NS::Base::volatileFunction() volatile\00"
60 // CHECK-DAG: private unnamed_addr constant [14 x i8] c"constFunction\00"
61 // CHECK-DAG: private unnamed_addr constant [37 x i8] c"void NS::Base::constFunction() const\00"
63 // CHECK-DAG: private unnamed_addr constant [26 x i8] c"functionReturingTemplate2\00"
64 // CHECK-DAG: private unnamed_addr constant [60 x i8] c"ClassTemplate<Base *> NS::Base::functionReturingTemplate2()\00"
66 // CHECK-DAG: private unnamed_addr constant [26 x i8] c"functionReturingTemplate1\00"
67 // CHECK-DAG: private unnamed_addr constant [57 x i8] c"ClassTemplate<int> NS::Base::functionReturingTemplate1()\00"
69 // CHECK-DAG: private unnamed_addr constant [23 x i8] c"withTemplateParameter2\00"
70 // CHECK-DAG: private unnamed_addr constant [61 x i8] c"void NS::Base::withTemplateParameter2(ClassTemplate<Base *>)\00"
72 // CHECK-DAG: private unnamed_addr constant [23 x i8] c"withTemplateParameter1\00"
73 // CHECK-DAG: private unnamed_addr constant [58 x i8] c"void NS::Base::withTemplateParameter1(ClassTemplate<int>)\00"
75 // CHECK-DAG: private unnamed_addr constant [23 x i8] c"functionReturningClass\00"
76 // CHECK-DAG: private unnamed_addr constant [41 x i8] c"Base *NS::Base::functionReturningClass()\00"
78 // CHECK-DAG: private unnamed_addr constant [23 x i8] c"functionWithParameters\00"
79 // CHECK-DAG: private unnamed_addr constant [60 x i8] c"void NS::Base::functionWithParameters(int, float *, Base *)\00"
81 // CHECK-DAG: private unnamed_addr constant [17 x i8] c"variadicFunction\00"
82 // CHECK-DAG: private unnamed_addr constant [42 x i8] c"void NS::Base::variadicFunction(int, ...)\00"
84 // CHECK-DAG: private unnamed_addr constant [41 x i8] c"virtual void NS::Base::virtualFunction()\00"
86 // CHECK-DAG: private unnamed_addr constant [15 x i8] c"inlineFunction\00"
87 // CHECK-DAG: private unnamed_addr constant [32 x i8] c"void NS::Base::inlineFunction()\00"
89 // CHECK-DAG: private unnamed_addr constant [15 x i8] c"staticFunction\00"
90 // CHECK-DAG: private unnamed_addr constant [39 x i8] c"static void NS::Base::staticFunction()\00"
92 // CHECK-DAG: private unnamed_addr constant [26 x i8] c"topLevelNamespaceFunction\00"
93 // CHECK-DAG: private unnamed_addr constant [59 x i8] c"void ClassInTopLevelNamespace::topLevelNamespaceFunction()\00"
95 // CHECK-DAG: private unnamed_addr constant [27 x i8] c"anonymousNamespaceFunction\00"
96 // CHECK-DAG: private unnamed_addr constant [84 x i8] c"void (anonymous namespace)::ClassInAnonymousNamespace::anonymousNamespaceFunction()\00"
98 // CHECK-DAG: private unnamed_addr constant [19 x i8] c"localClassFunction\00"
99 // CHECK-DAG: private unnamed_addr constant [59 x i8] c"void NS::localClass(int)::LocalClass::localClassFunction()\00"
103 int printf(const char * _Format, ...);
105 class ClassInTopLevelNamespace {
106 public:
107 void topLevelNamespaceFunction() {
108 printf("__func__ %s\n", __func__);
109 printf("__FUNCTION__ %s\n", __FUNCTION__);
110 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
114 namespace {
116 class ClassInAnonymousNamespace {
117 public:
118 void anonymousNamespaceFunction() {
119 printf("__func__ %s\n", __func__);
120 printf("__FUNCTION__ %s\n", __FUNCTION__);
121 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
125 } // end anonymous namespace
127 namespace NS {
129 template<typename T>
130 class ClassTemplate {
131 public:
132 void classTemplateFunction() {
133 printf("__func__ %s\n", __func__);
134 printf("__FUNCTION__ %s\n", __FUNCTION__);
135 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
139 class Base {
140 public:
141 static void staticFunction() {
142 printf("__func__ %s\n", __func__);
143 printf("__FUNCTION__ %s\n", __FUNCTION__);
144 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
147 inline void (inlineFunction)() {
148 printf("__func__ %s\n", __func__);
149 printf("__FUNCTION__ %s\n", __FUNCTION__);
150 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
153 virtual void virtualFunction() {
154 printf("__func__ %s\n", __func__);
155 printf("__FUNCTION__ %s\n", __FUNCTION__);
156 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
159 void functionWithParameters(int, float*, Base* base) {
160 printf("__func__ %s\n", __func__);
161 printf("__FUNCTION__ %s\n", __FUNCTION__);
162 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
165 Base *functionReturningClass() {
166 printf("__func__ %s\n", __func__);
167 printf("__FUNCTION__ %s\n", __FUNCTION__);
168 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
169 return 0;
172 void variadicFunction(int, ...) {
173 printf("__func__ %s\n", __func__);
174 printf("__FUNCTION__ %s\n", __FUNCTION__);
175 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
178 void withTemplateParameter1(ClassTemplate<int>) {
179 printf("__func__ %s\n", __func__);
180 printf("__FUNCTION__ %s\n", __FUNCTION__);
181 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
184 void withTemplateParameter2(ClassTemplate<Base *>) {
185 printf("__func__ %s\n", __func__);
186 printf("__FUNCTION__ %s\n", __FUNCTION__);
187 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
190 ClassTemplate<int> functionReturingTemplate1() {
191 printf("__func__ %s\n", __func__);
192 printf("__FUNCTION__ %s\n", __FUNCTION__);
193 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
194 return ClassTemplate<int>();
197 ClassTemplate<Base *> functionReturingTemplate2() {
198 printf("__func__ %s\n", __func__);
199 printf("__FUNCTION__ %s\n", __FUNCTION__);
200 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
201 return ClassTemplate<Base *>();
204 template<typename T>
205 void functionTemplate1(T t) {
206 printf("__func__ %s\n", __func__);
207 printf("__FUNCTION__ %s\n", __FUNCTION__);
208 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
211 void constFunction() const {
212 printf("__func__ %s\n", __func__);
213 printf("__FUNCTION__ %s\n", __FUNCTION__);
214 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
217 void volatileFunction() volatile {
218 printf("__func__ %s\n", __func__);
219 printf("__FUNCTION__ %s\n", __FUNCTION__);
220 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
223 void constVolatileFunction() const volatile {
224 printf("__func__ %s\n", __func__);
225 printf("__FUNCTION__ %s\n", __FUNCTION__);
226 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
229 void refQualifiedFunction() & {
230 printf("__func__ %s\n", __func__);
231 printf("__FUNCTION__ %s\n", __FUNCTION__);
232 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
235 void refQualifiedFunction() && {
236 printf("__func__ %s\n", __func__);
237 printf("__FUNCTION__ %s\n", __FUNCTION__);
238 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
242 class Derived : public Base {
243 public:
244 // Virtual function without being explicitly written.
245 void virtualFunction() {
246 printf("__func__ %s\n", __func__);
247 printf("__FUNCTION__ %s\n", __FUNCTION__);
248 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
252 class Constructor {
253 public:
254 Constructor() {
255 printf("__func__ %s\n", __func__);
256 printf("__FUNCTION__ %s\n", __FUNCTION__);
257 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
260 Constructor(int) {
261 printf("__func__ %s\n", __func__);
262 printf("__FUNCTION__ %s\n", __FUNCTION__);
263 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
266 Constructor(Base *) {
267 printf("__func__ %s\n", __func__);
268 printf("__FUNCTION__ %s\n", __FUNCTION__);
269 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
273 class Destructor {
274 public:
275 ~Destructor() {
276 printf("__func__ %s\n", __func__);
277 printf("__FUNCTION__ %s\n", __FUNCTION__);
278 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
282 class ContainerForAnonymousRecords {
283 public:
284 class {
285 public:
286 void anonymousClassFunction() {
287 printf("__func__ %s\n", __func__);
288 printf("__FUNCTION__ %s\n", __FUNCTION__);
289 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
291 } anonymousClass;
293 struct {
294 void anonymousStructFunction() {
295 printf("__func__ %s\n", __func__);
296 printf("__FUNCTION__ %s\n", __FUNCTION__);
297 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
299 } anonymousStruct;
301 union {
302 void anonymousUnionFunction() {
303 printf("__func__ %s\n", __func__);
304 printf("__FUNCTION__ %s\n", __FUNCTION__);
305 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
307 } anonymousUnion;
310 void localClass(int) {
311 class LocalClass {
312 public:
313 void localClassFunction() {
314 printf("__func__ %s\n", __func__);
315 printf("__FUNCTION__ %s\n", __FUNCTION__);
316 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
319 LocalClass lc;
320 lc.localClassFunction();
323 extern void externFunction() {
324 printf("__func__ %s\n", __func__);
325 printf("__FUNCTION__ %s\n", __FUNCTION__);
326 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
329 } // end NS namespace
331 // additional tests for __PRETTY_FUNCTION__
332 template <typename T, typename U>
333 void functionTemplateWithTwoParams(T, U)
335 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
338 template <typename T>
339 void functionTemplateWithoutParameterList()
341 T t = T();
343 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
346 template <typename T>
347 T functionTemplateWithTemplateReturnType()
349 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
351 return T();
354 template <typename T>
355 T * functionTemplateWithCompoundTypes(T a[])
357 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
359 return 0;
362 template <typename T>
363 void functionTemplateExplicitSpecialization(T t)
365 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
368 template <>
369 void functionTemplateExplicitSpecialization<int>(int i)
371 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
374 template <typename, typename T>
375 void functionTemplateWithUnnamedTemplateParameter(T t)
377 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
380 template <typename T>
381 void functionTemplateWithLambda(T t)
383 []() {
384 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
385 } ();
388 template <typename T>
389 void functionTemplateWithCapturedStmt(T t)
391 #pragma clang __debug captured
393 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
397 template <typename T>
398 class OuterClass
400 public:
401 class MiddleClass
403 public:
404 template <typename U>
405 class InnerClass
407 public:
408 void memberFunction(T x, U y) const
410 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
416 template <typename T, template <typename> class Param = NS::ClassTemplate>
417 class ClassWithTemplateTemplateParam
419 public:
420 static void staticMember()
422 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
426 template <int Count>
427 class NonTypeTemplateParam
429 public:
430 void size() const
432 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
436 template <typename T>
437 class SpecializedClassTemplate
439 public:
440 template <typename U>
441 void memberFunctionTemplate(T t, U u) const
443 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
447 template <>
448 class SpecializedClassTemplate<int>
450 public:
451 template <typename U>
452 void memberFunctionTemplate(int i, U u) const
454 printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
458 int main() {
459 ClassInAnonymousNamespace anonymousNamespace;
460 anonymousNamespace.anonymousNamespaceFunction();
462 ClassInTopLevelNamespace topLevelNamespace;
463 topLevelNamespace.topLevelNamespaceFunction();
465 NS::Base::staticFunction();
467 NS::Base b;
468 b.inlineFunction();
469 b.virtualFunction();
470 b.variadicFunction(0);
471 b.functionWithParameters(0, 0, 0);
472 b.functionReturningClass();
474 b.withTemplateParameter1(NS::ClassTemplate<int>());
475 b.withTemplateParameter2(NS::ClassTemplate<NS::Base *>());
476 b.functionReturingTemplate1();
477 b.functionReturingTemplate2();
478 b.functionTemplate1<int>(0);
479 b.functionTemplate1<NS::Base *>(0);
480 b.constFunction();
481 b.volatileFunction();
482 b.constVolatileFunction();
483 b.refQualifiedFunction();
484 NS::Base().refQualifiedFunction();
486 NS::Derived d;
487 d.virtualFunction();
489 NS::ClassTemplate<int> t1;
490 t1.classTemplateFunction();
491 NS::ClassTemplate<NS::Base *> t2;
492 t2.classTemplateFunction();
494 NS::Constructor c1;
495 NS::Constructor c2(0);
496 NS::Constructor c3((NS::Base *)0);
499 NS::Destructor destructor;
502 NS::ContainerForAnonymousRecords anonymous;
503 anonymous.anonymousClass.anonymousClassFunction();
504 anonymous.anonymousStruct.anonymousStructFunction();
505 anonymous.anonymousUnion.anonymousUnionFunction();
507 NS::localClass(0);
509 NS::externFunction();
511 // additional tests for __PRETTY_FUNCTION__
513 functionTemplateWithTwoParams(0, 0.0f);
514 functionTemplateWithoutParameterList<double>();
515 functionTemplateWithTemplateReturnType<char>();
516 int array[] = { 1, 2, 3 };
517 functionTemplateWithCompoundTypes(array);
518 functionTemplateExplicitSpecialization(0);
519 functionTemplateExplicitSpecialization(0.0);
520 functionTemplateWithUnnamedTemplateParameter<int, float>(0.0f);
522 functionTemplateWithLambda<int>(0);
523 functionTemplateWithCapturedStmt<int>(0);
525 OuterClass<int *>::MiddleClass::InnerClass<float> omi;
526 omi.memberFunction(0, 0.0f);
528 ClassWithTemplateTemplateParam<char>::staticMember();
530 NonTypeTemplateParam<42> ntt;
531 ntt.size();
533 SpecializedClassTemplate<int> sct1;
534 sct1.memberFunctionTemplate(0, 0.0f);
535 SpecializedClassTemplate<char> sct2;
536 sct2.memberFunctionTemplate('0', 0.0);
538 return 0;
541 // rdar://19065361
542 class XXX {
543 XXX();
544 ~XXX();
547 void XXLog(const char *functionName) { }
549 typedef void (^notify_handler_t)(int token);
551 typedef void (^dispatch_block_t)(void);
553 void notify_register_dispatch(notify_handler_t handler);
555 void _dispatch_once(dispatch_block_t block);
557 XXX::XXX()
559 _dispatch_once(^{ notify_register_dispatch( ^(int token) { XXLog(__FUNCTION__); });
562 // CHECK: define internal {{.*}}void @___ZN3XXXC2Ev_block_invoke_
564 XXX::~XXX()
566 _dispatch_once(^{ notify_register_dispatch( ^(int token) { XXLog(__FUNCTION__); });
569 // CHECK: define internal {{.*}}void @___ZN3XXXD2Ev_block_invoke_