[clang] [clang][dataflow] Handle CXXInheritedCtorInitExpr in ResultObjectVisitor. (PR #99616)
Pasquale Riello via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 24 08:29:58 PDT 2024
================
@@ -442,6 +442,46 @@ TEST_F(EnvironmentTest, CXXDefaultInitExprResultObjIsWrappedExprResultObj) {
&Env.getResultObjectLocation(*DefaultInit->getExpr()));
}
+TEST_F(EnvironmentTest, ResultObjectLocationForInheritedCtorInitExpr) {
+ using namespace ast_matchers;
+
+ std::string Code = R"(
+ struct Base {
+ Base(int b) {}
+ };
+ struct Derived : Base {
+ using Base::Base;
+ };
+
+ Derived d = Derived(0);
+ )";
+
+ auto Unit =
+ tooling::buildASTFromCodeWithArgs(Code, {"-fsyntax-only", "-std=c++20"});
+ auto &Context = Unit->getASTContext();
+
+ ASSERT_EQ(Context.getDiagnostics().getClient()->getNumErrors(), 0U);
+
+ auto Results =
+ match(cxxConstructorDecl(
+ hasAnyConstructorInitializer(cxxCtorInitializer(
+ withInitializer(expr().bind("inherited_ctor_init_expr")))))
+ .bind("ctor"),
+ Context);
+ const auto *Constructor = selectFirst<CXXConstructorDecl>("ctor", Results);
+ const auto *InheritedCtorInit =
+ selectFirst<CXXInheritedCtorInitExpr>("inherited_ctor_init_expr", Results);
+
+ // Verify that `inherited_ctor_init_expr` has no children.
+ ASSERT_EQ(InheritedCtorInit->child_begin(), InheritedCtorInit->child_end());
+
+ Environment Env(DAContext, *Constructor);
+ Env.initialize();
+
+ RecordStorageLocation &Loc = Env.getResultObjectLocation(*InheritedCtorInit);
+ ASSERT_NE(&Loc, nullptr);
----------------
Pask00 wrote:
You are right, thanks for the suggestion!
https://github.com/llvm/llvm-project/pull/99616
More information about the cfe-commits
mailing list