xref: /llvm-project/lldb/test/API/commands/expression/completion-crash-invalid-iterator/main.cpp (revision 99451b4453688a94c6014cac233d371ab4cc342d)
1*99451b44SJordan Rupprecht class LoadedByParamClass {};
2*99451b44SJordan Rupprecht struct ParamClass {
3*99451b44SJordan Rupprecht   LoadedByParamClass some_func();
4*99451b44SJordan Rupprecht };
5*99451b44SJordan Rupprecht struct SomeClass {
6*99451b44SJordan Rupprecht   // LLDB stops in the constructor and then requests
7*99451b44SJordan Rupprecht   // possible expression completions. This will iterate over the
8*99451b44SJordan Rupprecht   // declarations in the translation unit.
9*99451b44SJordan Rupprecht   // The unnamed ParamClass parameter causes that LLDB will add
10*99451b44SJordan Rupprecht   // an incomplete ParamClass decl to the translation unit which
11*99451b44SJordan Rupprecht   // the code completion will find. Upon inspecting the ParamClass
12*99451b44SJordan Rupprecht   // decl to see if it can be used to provide any useful completions,
13*99451b44SJordan Rupprecht   // Clang will complete it and load all its members.
14*99451b44SJordan Rupprecht   // This causes that its member function some_func is loaded which in turn
15*99451b44SJordan Rupprecht   // loads the LoadedByParamClass decl. When LoadedByParamClass
16*99451b44SJordan Rupprecht   // is created it will be added to the translation unit which
17*99451b44SJordan Rupprecht   // will invalidate all iterators that currently iterate over
18*99451b44SJordan Rupprecht   // the translation unit. The iterator we use for code completion
19*99451b44SJordan Rupprecht   // is now invalidated and LLDB crashes.
SomeClassSomeClass20*99451b44SJordan Rupprecht   SomeClass(ParamClass) {}
21*99451b44SJordan Rupprecht };
main()22*99451b44SJordan Rupprecht int main() { ParamClass e; SomeClass y(e); }
23