diff --git a/clang/lib/StaticAnalyzer/Core/MemRegion.cpp b/clang/lib/StaticAnalyzer/Core/MemRegion.cpp index 86e33969d21b..632a381a398e 100644 --- a/clang/lib/StaticAnalyzer/Core/MemRegion.cpp +++ b/clang/lib/StaticAnalyzer/Core/MemRegion.cpp @@ -1022,7 +1022,8 @@ MemRegionManager::getCXXThisRegion(QualType thisPointerTy, // 'this' refers to a this to the enclosing scope, there is no right region to // return. while (!LC->inTopFrame() && - (!D || PT != D->getThisType(getContext())->getAs())) { + (!D || D->isStatic() || + PT != D->getThisType(getContext())->getAs())) { LC = LC->getParent(); D = dyn_cast(LC->getDecl()); } diff --git a/clang/test/Analysis/lambdas.cpp b/clang/test/Analysis/lambdas.cpp index 18b2e416315b..36af7e1e84e4 100644 --- a/clang/test/Analysis/lambdas.cpp +++ b/clang/test/Analysis/lambdas.cpp @@ -186,6 +186,12 @@ struct DontCrash { int x; void f() { callLambda([&](){ ++x; }); + callLambdaFromStatic([&](){ ++x; }); + } + + template + static void callLambdaFromStatic(T t) { + t(); } };