// Check if type is a C++ class with non-trivial destructor.
if (const CXXRecordDecl *CD = QT->getAsCXXRecordDecl())
- if (!CD->hasTrivialDestructor()) {
+ if (CD->hasDefinition() && !CD->hasTrivialDestructor()) {
// Add the variable to scope
Scope = createOrReuseLocalScope(Scope);
Scope->addVar(VD);
if (!Body)
return;
TheBuildResult = SawFunctionBody;
- if (CFG::buildCFG(nullptr, Body, Result.Context, CFG::BuildOptions()))
+ CFG::BuildOptions Options;
+ Options.AddImplicitDtors = true;
+ if (CFG::buildCFG(nullptr, Body, Result.Context, Options))
TheBuildResult = BuiltCFG;
}
};
EXPECT_EQ(BuiltCFG, BuildCFG(Code));
}
+// Constructing a CFG on a function template with a variable of incomplete type
+// should not crash.
+TEST(CFG, VariableOfIncompleteType) {
+ const char *Code = "template<class T> void f() {\n"
+ " class Undefined;\n"
+ " Undefined u;\n"
+ "}\n";
+ EXPECT_EQ(BuiltCFG, BuildCFG(Code));
+}
+
} // namespace
} // namespace analysis
} // namespace clang