78 lines · cpp
1// RUN: %clang_cc1 -triple x86_64-apple-darwin10.0.0 -fblocks -emit-llvm -o - %s -fexceptions -std=c++11 | FileCheck %s2// RUN: %clang_cc1 -triple x86_64-apple-darwin10.0.0 -fblocks -emit-llvm -o - %s -fexceptions -std=c++14 | FileCheck --check-prefixes=CHECK,CXX14 %s3 4// CHECK-LABEL: define{{.*}} void @_ZN19non_inline_function3fooEv()5// CHECK-LABEL: define internal void @"_ZZN19non_inline_function3fooEvENK3$_0clEi"(ptr6// CHECK-LABEL: define internal noundef signext i8 @"_ZZZN19non_inline_function3fooEvENK3$_0clEiENKUlcE_clEc"(ptr7namespace non_inline_function {8void foo() {9 auto L = [](int a) {10 return [](char b) {11 return b;12 };13 };14 L(3)('a');15}16}17 18namespace non_template {19 struct L {20 int t = ([](int a) { return [](int b) { return b; };})(2)(3); 21 };22 L l; 23}24 25// It's important that this is not in a namespace; we're testing the mangling26// of lambdas in top-level inline variables here.27inline auto lambda_in_inline_variable = [] {};28template<typename T> struct Wrap {};29// CHECK-LABEL: define {{.*}} @_Z30test_lambda_in_inline_variable4WrapIN25lambda_in_inline_variableMUlvE_EE30void test_lambda_in_inline_variable(Wrap<decltype(lambda_in_inline_variable)>) {}31 32namespace lambdas_in_NSDMIs_template_class {33template<class T>34struct L {35 T t2 = ([](int a) { return [](int b) { return b; };})(T{})(T{}); 36};37L<int> l;38}39 40// CHECK-LABEL: define linkonce_odr noundef i32 @_ZN15inline_function3fooEv41 42// CHECK-LABEL: define linkonce_odr void @_ZNK12non_template1L1tMUliE_clEi(ptr43// CHECK-LABEL: define linkonce_odr noundef i32 @_ZZNK12non_template1L1tMUliE_clEiENKUliE_clEi(ptr44 45 46// CHECK-LABEL: define linkonce_odr void @_ZNK32lambdas_in_NSDMIs_template_class1LIiEUliE_clEi(ptr47// CHECK-LABEL: define linkonce_odr noundef i32 @_ZZNK32lambdas_in_NSDMIs_template_class1LIiEUliE_clEiENKUliE_clEi(ptr48 49// CHECK-LABEL: define linkonce_odr void @_ZZN15inline_function3fooEvENKUliE_clEi50// CHECK-LABEL: define linkonce_odr noundef signext i8 @_ZZZN15inline_function3fooEvENKUliE_clEiENKUlcE_clEc51namespace inline_function {52inline int foo() {53 auto L = [](int a) {54 return [](char b) {55 return b;56 };57 };58 L(3)('a');59 return 0;60}61int use = foo();62}63 64#if __cplusplus >= 201402L65// CXX14-LABEL: define internal void @"_ZZZN32lambda_capture_in_generic_lambda3fooIiEEDavENKUlT_E_clIZNS_L1fEvE3$_0EEDaS1_ENKUlvE_clEv"66namespace lambda_capture_in_generic_lambda {67template <typename T> auto foo() {68 return [](auto func) {69 [func] { func(); }();70 };71}72static void f() {73 foo<int>()([] { });74}75void f1() { f(); }76}77#endif78