Index: clang/lib/AST/MicrosoftMangle.cpp =================================================================== --- clang/lib/AST/MicrosoftMangle.cpp +++ clang/lib/AST/MicrosoftMangle.cpp @@ -947,12 +947,11 @@ mangleSourceName(Name); - // If the context of a closure type is an initializer for a class - // member (static or nonstatic), it is encoded in a qualified name. + // If the context is a variable or a class member, it is encoded + // in a qualified name. if (LambdaManglingNumber && LambdaContextDecl) { if ((isa(LambdaContextDecl) || - isa(LambdaContextDecl)) && - LambdaContextDecl->getDeclContext()->isRecord()) { + isa(LambdaContextDecl))) { mangleUnqualifiedName(cast(LambdaContextDecl)); } } Index: clang/test/CodeGenCXX/mangle-ms-cxx11.cpp =================================================================== --- clang/test/CodeGenCXX/mangle-ms-cxx11.cpp +++ clang/test/CodeGenCXX/mangle-ms-cxx11.cpp @@ -337,10 +337,10 @@ }(); using FPtrTy = void(void); static void default_args(FPtrTy x = [] {}, FPtrTy y = [] {}, int z = [] { return 1; }() + [] { return 2; }()) {} - // CHECK-DAG: @"??R@?0??default_args@A@PR31197@@SAXP6AXXZ0H@Z@QBE@XZ"( - // CHECK-DAG: @"??R@?0??default_args@A@PR31197@@SAXP6AXXZ0H@Z@QBE@XZ"( - // CHECK-DAG: @"??R@?0??default_args@A@PR31197@@SAXP6AXXZ0H@Z@QBE@XZ"( - // CHECK-DAG: @"??R@?0??default_args@A@PR31197@@SAXP6AXXZ0H@Z@QBE@XZ"( + // CHECK-DAG: @"??R@z@?0??default_args@A@PR31197@@SAXP6AXXZ0H@Z@QBE@XZ"( + // CHECK-DAG: @"??R@z@?0??default_args@A@PR31197@@SAXP6AXXZ0H@Z@QBE@XZ"( + // CHECK-DAG: @"??R@y@?0??default_args@A@PR31197@@SAXP6AXXZ0H@Z@QBE@XZ"( + // CHECK-DAG: @"??R@x@?0??default_args@A@PR31197@@SAXP6AXXZ0H@Z@QBE@XZ"( }; A a; Index: clang/test/CodeGenCXX/mangle-ms-cxx17.cpp =================================================================== --- clang/test/CodeGenCXX/mangle-ms-cxx17.cpp +++ clang/test/CodeGenCXX/mangle-ms-cxx17.cpp @@ -19,3 +19,11 @@ // CHECK-DAG: "?$S4@@3US@@B" const auto [x2, y2] = f(); + +// CHECK-DAG: "?i1@@3V@0@B" +inline const auto i1 = [](auto x) { return 0; }; +// CHECK-DAG: "?i2@@3V@0@B" +inline const auto i2 = [](auto x) { return 1; }; +// CHECK-DAG: "??$?RH@@i1@@QBE?A?@@H@Z" +// CHECK-DAG: "??$?RH@@i2@@QBE?A?@@H@Z" +int g() {return i1(1) + i2(1); }