xref: /llvm-project/clang/test/CXX/drs/cwg177x.cpp (revision 463e61a0013253bec1b5e7f07e7b1803b68e2b3d)
1ed128c7dSVlad Serebrennikov // RUN: %clang_cc1 -std=c++98 %s -fexceptions -fcxx-exceptions -pedantic-errors -ast-dump | FileCheck %s
2ed128c7dSVlad Serebrennikov // RUN: %clang_cc1 -std=c++11 %s -fexceptions -fcxx-exceptions -pedantic-errors -ast-dump | FileCheck %s --check-prefixes=CHECK,CXX11
3ed128c7dSVlad Serebrennikov // RUN: %clang_cc1 -std=c++14 %s -fexceptions -fcxx-exceptions -pedantic-errors -ast-dump | FileCheck %s --check-prefixes=CHECK,CXX11,CXX14
4327e2b7cSVlad Serebrennikov // RUN: %clang_cc1 -std=c++17 %s -fexceptions -fcxx-exceptions -pedantic-errors -ast-dump | FileCheck %s --check-prefixes=CHECK,CXX11,CXX14
5327e2b7cSVlad Serebrennikov // RUN: %clang_cc1 -std=c++20 %s -fexceptions -fcxx-exceptions -pedantic-errors -ast-dump | FileCheck %s --check-prefixes=CHECK,CXX11,CXX14
6327e2b7cSVlad Serebrennikov // RUN: %clang_cc1 -std=c++23 %s -fexceptions -fcxx-exceptions -pedantic-errors -ast-dump | FileCheck %s --check-prefixes=CHECK,CXX11,CXX14
7327e2b7cSVlad Serebrennikov // RUN: %clang_cc1 -std=c++2c %s -fexceptions -fcxx-exceptions -pedantic-errors -ast-dump | FileCheck %s --check-prefixes=CHECK,CXX11,CXX14
8ed128c7dSVlad Serebrennikov // RUN: %clang_cc1 -std=c++1z %s -fexceptions -fcxx-exceptions -pedantic-errors -triple i386-windows-pc -ast-dump | FileCheck %s --check-prefixes=CHECK,CXX11,CXX14
9ed128c7dSVlad Serebrennikov 
10ed128c7dSVlad Serebrennikov namespace cwg1772 { // cwg1772: 14
11ed128c7dSVlad Serebrennikov   // __func__ in a lambda should name operator(), not the containing function.
12ed128c7dSVlad Serebrennikov   // CHECK: NamespaceDecl{{.+}}cwg1772
13ed128c7dSVlad Serebrennikov #if __cplusplus >= 201103L
14ed128c7dSVlad Serebrennikov   auto x = []() { __func__; };
15ed128c7dSVlad Serebrennikov   // CXX11: LambdaExpr
16ed128c7dSVlad Serebrennikov   // CXX11: CXXRecordDecl
17ed128c7dSVlad Serebrennikov   // CXX11: CXXMethodDecl{{.+}} operator() 'void () {{.*}}const'
18ed128c7dSVlad Serebrennikov   // CXX11-NEXT: CompoundStmt
19ed128c7dSVlad Serebrennikov   // CXX11-NEXT: PredefinedExpr{{.+}} 'const char[11]' lvalue __func__
20ed128c7dSVlad Serebrennikov   // CXX11-NEXT: StringLiteral{{.+}} 'const char[11]' lvalue "operator()"
21ed128c7dSVlad Serebrennikov 
22ed128c7dSVlad Serebrennikov   void func() {
23ed128c7dSVlad Serebrennikov     // CXX11: FunctionDecl{{.+}} func
24ed128c7dSVlad Serebrennikov   (void)[]() { __func__; };
25ed128c7dSVlad Serebrennikov   // CXX11-NEXT: CompoundStmt
26ed128c7dSVlad Serebrennikov   // CXX11: LambdaExpr
27ed128c7dSVlad Serebrennikov   // CXX11: CXXRecordDecl
28ed128c7dSVlad Serebrennikov   // CXX11: CXXMethodDecl{{.+}} operator() 'void () {{.*}}const'
29ed128c7dSVlad Serebrennikov   // CXX11-NEXT: CompoundStmt
30ed128c7dSVlad Serebrennikov   // CXX11-NEXT: PredefinedExpr{{.+}} 'const char[11]' lvalue __func__
31ed128c7dSVlad Serebrennikov   // CXX11-NEXT: StringLiteral{{.+}} 'const char[11]' lvalue "operator()"
32ed128c7dSVlad Serebrennikov   }
33ed128c7dSVlad Serebrennikov #endif // __cplusplus >= 201103L
34*463e61a0SVlad Serebrennikov } // namespace cwg1772
35ed128c7dSVlad Serebrennikov 
36ed128c7dSVlad Serebrennikov namespace cwg1779 { // cwg1779: 14
37ed128c7dSVlad Serebrennikov   // __func__ in a function template, member function template, or generic
38ed128c7dSVlad Serebrennikov   //  lambda should have a dependent type.
39ed128c7dSVlad Serebrennikov   // CHECK: NamespaceDecl{{.+}}cwg1779
40ed128c7dSVlad Serebrennikov 
41ed128c7dSVlad Serebrennikov   template<typename T>
42ed128c7dSVlad Serebrennikov   void FuncTemplate() {
43ed128c7dSVlad Serebrennikov     __func__;
44ed128c7dSVlad Serebrennikov     // CHECK: FunctionDecl{{.+}} FuncTemplate
45ed128c7dSVlad Serebrennikov     // CHECK-NEXT: CompoundStmt
46ed128c7dSVlad Serebrennikov     // CHECK-NEXT: PredefinedExpr{{.+}} '<dependent type>' lvalue __func__
47ed128c7dSVlad Serebrennikov   }
48ed128c7dSVlad Serebrennikov 
49ed128c7dSVlad Serebrennikov   template<typename T>
50ed128c7dSVlad Serebrennikov   class ClassTemplate {
51ed128c7dSVlad Serebrennikov     // CHECK: ClassTemplateDecl{{.+}} ClassTemplate
52ed128c7dSVlad Serebrennikov     void MemFunc() {
53ed128c7dSVlad Serebrennikov       // CHECK: CXXMethodDecl{{.+}} MemFunc 'void (){{.*}}'
54ed128c7dSVlad Serebrennikov       // CHECK-NEXT: CompoundStmt
55ed128c7dSVlad Serebrennikov       // CHECK-NEXT: PredefinedExpr{{.+}} '<dependent type>' lvalue __func__
56ed128c7dSVlad Serebrennikov       __func__;
57ed128c7dSVlad Serebrennikov     }
58ed128c7dSVlad Serebrennikov     void OutOfLineMemFunc();
59ed128c7dSVlad Serebrennikov   };
60ed128c7dSVlad Serebrennikov 
61ed128c7dSVlad Serebrennikov   template <typename T> void ClassTemplate<T>::OutOfLineMemFunc() {
62ed128c7dSVlad Serebrennikov     // CHECK: CXXMethodDecl{{.+}}parent{{.+}} OutOfLineMemFunc 'void (){{.*}}'
63ed128c7dSVlad Serebrennikov     // CHECK-NEXT: CompoundStmt
64ed128c7dSVlad Serebrennikov     // CHECK-NEXT: PredefinedExpr{{.+}} '<dependent type>' lvalue __func__
65ed128c7dSVlad Serebrennikov     __func__;
66ed128c7dSVlad Serebrennikov   }
67ed128c7dSVlad Serebrennikov 
68ed128c7dSVlad Serebrennikov #if __cplusplus >= 201402L
69ed128c7dSVlad Serebrennikov   void contains_generic_lambda() {
70ed128c7dSVlad Serebrennikov     // CXX14: FunctionDecl{{.+}}contains_generic_lambda
71ed128c7dSVlad Serebrennikov     // CXX14: LambdaExpr
72ed128c7dSVlad Serebrennikov     // CXX14: CXXRecordDecl
73ed128c7dSVlad Serebrennikov     // CXX14: CXXMethodDecl{{.+}} operator() 'auto (auto) {{.*}}const'
74ed128c7dSVlad Serebrennikov     // CXX14-NEXT: ParmVarDecl
75ed128c7dSVlad Serebrennikov     // CXX14-NEXT: CompoundStmt
76ed128c7dSVlad Serebrennikov     // CXX14-NEXT: PredefinedExpr{{.+}} '<dependent type>' lvalue __func__
77ed128c7dSVlad Serebrennikov     (void)[](auto x) {
78ed128c7dSVlad Serebrennikov       __func__;
79ed128c7dSVlad Serebrennikov     };
80ed128c7dSVlad Serebrennikov   }
81ed128c7dSVlad Serebrennikov #endif // __cplusplus >= 201402L
82*463e61a0SVlad Serebrennikov } // namespace cwg1779
83