[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / CXX / drs / cwg177x.cpp
blobcc62bdac4cf06aaa5e26dba0724895180bc0ef6f
1 // RUN: %clang_cc1 -std=c++98 %s -fexceptions -fcxx-exceptions -pedantic-errors -ast-dump | FileCheck %s
2 // RUN: %clang_cc1 -std=c++11 %s -fexceptions -fcxx-exceptions -pedantic-errors -ast-dump | FileCheck %s --check-prefixes=CHECK,CXX11
3 // RUN: %clang_cc1 -std=c++14 %s -fexceptions -fcxx-exceptions -pedantic-errors -ast-dump | FileCheck %s --check-prefixes=CHECK,CXX11,CXX14
4 // RUN: %clang_cc1 -std=c++1z %s -fexceptions -fcxx-exceptions -pedantic-errors -ast-dump | FileCheck %s --check-prefixes=CHECK,CXX11,CXX14
5 // 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
7 namespace cwg1772 { // cwg1772: 14
8 // __func__ in a lambda should name operator(), not the containing function.
9 // CHECK: NamespaceDecl{{.+}}cwg1772
10 #if __cplusplus >= 201103L
11 auto x = []() { __func__; };
12 // CXX11: LambdaExpr
13 // CXX11: CXXRecordDecl
14 // CXX11: CXXMethodDecl{{.+}} operator() 'void () {{.*}}const'
15 // CXX11-NEXT: CompoundStmt
16 // CXX11-NEXT: PredefinedExpr{{.+}} 'const char[11]' lvalue __func__
17 // CXX11-NEXT: StringLiteral{{.+}} 'const char[11]' lvalue "operator()"
19 void func() {
20 // CXX11: FunctionDecl{{.+}} func
21 (void)[]() { __func__; };
22 // CXX11-NEXT: CompoundStmt
23 // CXX11: LambdaExpr
24 // CXX11: CXXRecordDecl
25 // CXX11: CXXMethodDecl{{.+}} operator() 'void () {{.*}}const'
26 // CXX11-NEXT: CompoundStmt
27 // CXX11-NEXT: PredefinedExpr{{.+}} 'const char[11]' lvalue __func__
28 // CXX11-NEXT: StringLiteral{{.+}} 'const char[11]' lvalue "operator()"
30 #endif // __cplusplus >= 201103L
33 namespace cwg1779 { // cwg1779: 14
34 // __func__ in a function template, member function template, or generic
35 // lambda should have a dependent type.
36 // CHECK: NamespaceDecl{{.+}}cwg1779
38 template<typename T>
39 void FuncTemplate() {
40 __func__;
41 // CHECK: FunctionDecl{{.+}} FuncTemplate
42 // CHECK-NEXT: CompoundStmt
43 // CHECK-NEXT: PredefinedExpr{{.+}} '<dependent type>' lvalue __func__
46 template<typename T>
47 class ClassTemplate {
48 // CHECK: ClassTemplateDecl{{.+}} ClassTemplate
49 void MemFunc() {
50 // CHECK: CXXMethodDecl{{.+}} MemFunc 'void (){{.*}}'
51 // CHECK-NEXT: CompoundStmt
52 // CHECK-NEXT: PredefinedExpr{{.+}} '<dependent type>' lvalue __func__
53 __func__;
55 void OutOfLineMemFunc();
58 template <typename T> void ClassTemplate<T>::OutOfLineMemFunc() {
59 // CHECK: CXXMethodDecl{{.+}}parent{{.+}} OutOfLineMemFunc 'void (){{.*}}'
60 // CHECK-NEXT: CompoundStmt
61 // CHECK-NEXT: PredefinedExpr{{.+}} '<dependent type>' lvalue __func__
62 __func__;
65 #if __cplusplus >= 201402L
66 void contains_generic_lambda() {
67 // CXX14: FunctionDecl{{.+}}contains_generic_lambda
68 // CXX14: LambdaExpr
69 // CXX14: CXXRecordDecl
70 // CXX14: CXXMethodDecl{{.+}} operator() 'auto (auto) {{.*}}const'
71 // CXX14-NEXT: ParmVarDecl
72 // CXX14-NEXT: CompoundStmt
73 // CXX14-NEXT: PredefinedExpr{{.+}} '<dependent type>' lvalue __func__
74 (void)[](auto x) {
75 __func__;
78 #endif // __cplusplus >= 201402L