================ @@ -442,6 +442,55 @@ TEST_F(EnvironmentTest, CXXDefaultInitExprResultObjIsWrappedExprResultObj) { &Env.getResultObjectLocation(*DefaultInit->getExpr())); } +// This test verifies the behavior of `getResultObjectLocation()` in +// scenarios involving inherited constructors. +// Since the specific AST node of interest `CXXConstructorDecl` is implicitly +// generated, we cannot annotate any statements inside of it as we do in tests +// within TransferTest. Thus, the only way to get the right `Environment` is by +// explicitly initializing it as we do in tests within EnvironmentTest. +// This is why this test is not inside TransferTest, where most of the tests for +// `getResultObjectLocation()` are located. +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); + + EXPECT_EQ(InheritedCtorInit->child_begin(), InheritedCtorInit->child_end()); + + Environment Env(DAContext, *Constructor); + Env.initialize(); + + RecordStorageLocation &Loc = Env.getResultObjectLocation(*InheritedCtorInit); + EXPECT_NE(&Loc, nullptr); + + ASSERT_EQ(&Loc, Env.getThisPointeeStorageLocation()); ---------------- martinboehme wrote:
```suggestion EXPECT_EQ(&Loc, Env.getThisPointeeStorageLocation()); ``` https://github.com/llvm/llvm-project/pull/99616 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits