================
@@ -2371,6 +2371,128 @@ TEST(TransferTest, DefaultInitializer) {
       });
 }
 
+TEST(TransferTest, DefaultInitializerInAggregateInit) {
+  // `this` inside the default member initializer for `Baz` denotes the object
+  // the list-initialization creates, not the enclosing function's object, so
+  // `Baz` binds to that object's `Bar`.
+  std::string Code = R"(
+    struct S {
+      int Bar;
+      int &Baz = this->Bar;
+    };
+    void target(int Foo) {
+      S Var = {Foo};
+      int &Qux = Var.Baz;
+      // [[p]]
+    }
+  )";
+  runDataflow(
+      Code,
+      [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+         ASTContext &ASTCtx) {
+        ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+        const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+        // `target` is not a member function, so there is no enclosing object.
+        EXPECT_THAT(Env.getThisPointeeStorageLocation(), IsNull());
+
+        const ValueDecl *VarDecl = findValueDecl(ASTCtx, "Var");
+        ASSERT_THAT(VarDecl, NotNull());
+        const auto *VarLoc =
+            cast<RecordStorageLocation>(Env.getStorageLocation(*VarDecl));
+        const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
+        ASSERT_THAT(BarDecl, NotNull());
+
+        const ValueDecl *QuxDecl = findValueDecl(ASTCtx, "Qux");
+        ASSERT_THAT(QuxDecl, NotNull());
+        EXPECT_EQ(Env.getStorageLocation(*QuxDecl),
+                  VarLoc->getChild(*cast<FieldDecl>(BarDecl)));
+      });
+}
+
----------------
jvoung wrote:

could you add or extend a test case where there are multiple InitList instances 
and check that the getChild storage locations are distinct? 

Maybe a paren list test as well in case?

https://github.com/llvm/llvm-project/pull/221299
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to