[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / Modules / lambda-context.cpp
blob6ce482c2b763e19215f7efc0d99075e41ec55dd0
1 // RUN: %clang_cc1 -fmodules -std=c++11 -emit-pch -o %t %s
2 // RUN: %clang_cc1 -fmodules -std=c++11 -include-pch %t %s -verify
3 //
4 // This test checks for a bug in the deserialization code that was only
5 // reachable with modules enabled, but actually building and using modules is
6 // not necessary in order to trigger it, so we just use PCH here to make the
7 // test simpler.
9 #ifndef HEADER_INCLUDED
10 #define HEADER_INCLUDED
12 struct X { template <typename T> X(T) {} };
13 struct Y { Y(X x = [] {}); };
15 #else
17 // This triggers us to load the specialization of X::X for Y's lambda. That
18 // lambda's context decl must not be loaded as a result of loading the lambda,
19 // as that would hit a deserialization cycle.
20 X x = [] {}; // expected-no-diagnostics
22 #endif