@@ -415,3 +415,43 @@ TEST(ObjectAddress, AMembersOutsideSourceIsImmuneToAnotherMemberListingIt) {
415415 // Filed under its declaring member, not at the root's flat address.
416416 EXPECT_NE (alone.generic_string ().find (" obj/core/" ), std::string::npos) << alone;
417417}
418+
419+ // The same for a file inside ANOTHER member's directory: the member that
420+ // contains it may be outside the selection, and then the virtual root contains
421+ // the file instead. The address is the file's place in the workspace.
422+ TEST (ObjectAddress, AMembersSourceInAnotherMembersDirectoryIsImmuneToTheSelection) {
423+ Tmp t;
424+ const auto ws = t.path / " ws" ;
425+ auto plan_with = [&](bool withLib) -> std::filesystem::path {
426+ mcpp::manifest::Manifest root;
427+ root.package .name = " workspace" ;
428+ root.package .version = " 0.0.0" ;
429+ root.package .standard = " c++23" ;
430+ root.package .virtualRoot = true ;
431+ std::vector<mcpp::modgraph::PackageRoot> packages;
432+ auto rootPkg = makePackage (ws, " workspace" );
433+ rootPkg.manifest = root;
434+ packages.push_back (rootPkg);
435+ packages.push_back (makePackage (ws / " app" , " app" ));
436+ if (withLib) packages.push_back (makePackage (ws / " lib" , " lib" ));
437+
438+ mcpp::modgraph::Graph graph;
439+ graph.units .push_back (unitFor (ws / " app" , " ../lib/src/shared.c" , " app" ));
440+ if (withLib) graph.units .push_back (unitFor (ws / " lib" , " src/lib.c" , " lib" ));
441+ std::vector<std::size_t > topo;
442+ for (std::size_t i = 0 ; i < graph.units .size (); ++i) topo.push_back (i);
443+ auto plan = make_plan (root, gccLike (), {}, graph, topo, packages, ws,
444+ ws / " target" / " t" , {}, {}, {});
445+ EXPECT_TRUE (plan) << (plan ? std::string{} : plan.error ());
446+ if (!plan) return {};
447+ for (auto const & cu : plan->compileUnits )
448+ if (cu.packageName == " app" ) return cu.object ;
449+ ADD_FAILURE () << " app's unit is not in the plan" ;
450+ return {};
451+ };
452+ const auto alone = plan_with (false );
453+ const auto beside = plan_with (true );
454+ EXPECT_FALSE (alone.empty ());
455+ EXPECT_EQ (alone, beside);
456+ EXPECT_NE (alone.generic_string ().find (" obj/app/__ws/lib/src/" ), std::string::npos) << alone;
457+ }
0 commit comments