@@ -60,16 +60,19 @@ mcpp::modgraph::PackageRoot package(const std::filesystem::path& root, std::stri
6060 return p;
6161}
6262
63+ // `provides` is empty for a unit that provides no module. A plain string and
64+ // not an `std::optional<std::string>`, which does not construct under clang
65+ // with the MSVC STL (see `CompileUnit::providesModule`).
6366mcpp::modgraph::SourceUnit unit (const std::filesystem::path& root, std::string_view rel,
64- std::string_view pkg, std::optional<std::string> provides,
67+ std::string_view pkg, std::string_view provides,
6568 std::vector<std::string> requires_) {
6669 mcpp::modgraph::SourceUnit u;
6770 u.path = root / rel;
6871 u.relPath = std::filesystem::path (rel);
6972 u.packageName = std::string (pkg);
70- u.kind = provides ? mcpp::SourceKind::ModuleInterface : mcpp::SourceKind::Cxx ;
71- if (provides) {
72- u.provides = mcpp::modgraph::ModuleId{* provides};
73+ u.kind = provides. empty () ? mcpp::SourceKind::Cxx : mcpp::SourceKind::ModuleInterface ;
74+ if (! provides. empty () ) {
75+ u.provides = mcpp::modgraph::ModuleId{std::string ( provides) };
7376 u.providesInterface = true ;
7477 u.declaration = mcpp::modgraph::ModuleDeclaration::Interface;
7578 }
@@ -136,10 +139,10 @@ std::expected<BuildPlan, std::string> plan_workspace(const Tmp& t, mcpp::toolcha
136139 mcpp::modgraph::Graph graph;
137140 graph.units .push_back (unit (ws / " core" , " src/m.cppm" , " core" , " m" , {" std" }));
138141 graph.units .push_back (unit (ws / " core" , " src/core.cppm" , " core" , " corelib" , {" m" }));
139- graph.units .push_back (unit (ws / " app" , " src/main.cpp" , " app" , std:: nullopt , {" corelib" }));
142+ graph.units .push_back (unit (ws / " app" , " src/main.cpp" , " app" , " " , {" corelib" }));
140143 if (withTool) {
141144 graph.units .push_back (unit (ws / " tool" , " src/m.cppm" , " tool" , " m" , {}));
142- graph.units .push_back (unit (ws / " tool" , " src/main.cpp" , " tool" , std:: nullopt , {" m" }));
145+ graph.units .push_back (unit (ws / " tool" , " src/main.cpp" , " tool" , " " , {" m" }));
143146 }
144147 for (std::size_t i = 0 ; i < graph.units .size (); ++i)
145148 if (auto const & p = graph.units [i].provides )
@@ -235,7 +238,7 @@ TEST(ModuleAddress, RootModulesStayFlatAndNeedNoMap) {
235238
236239 mcpp::modgraph::Graph graph;
237240 graph.units .push_back (unit (proj, " src/m.cppm" , " app" , " m" , {" std" }));
238- graph.units .push_back (unit (proj, " src/main.cpp" , " app" , std:: nullopt , {" m" , " std" }));
241+ graph.units .push_back (unit (proj, " src/main.cpp" , " app" , " " , {" m" , " std" }));
239242 graph.providersOf [" m" ] = {0 };
240243 graph.producerOf [" m" ] = 0 ;
241244 graph.closures [" app" ] = {" app" };
@@ -274,7 +277,7 @@ TEST(ModuleAddress, PositionIndependenceFollowsTheTargetNotTheGraph) {
274277 rootPkg.manifest = root;
275278 packages.push_back (rootPkg);
276279 mcpp::modgraph::Graph graph;
277- graph.units .push_back (unit (proj, " src/main.cpp" , " fw" , std:: nullopt , {}));
280+ graph.units .push_back (unit (proj, " src/main.cpp" , " fw" , " " , {}));
278281 auto tc = toolchain (mcpp::toolchain::CompilerId::GCC );
279282 tc.targetTriple = " arm-none-eabi" ;
280283 auto plan = make_plan (root, tc, {}, graph, {0 }, packages, proj, proj / " target" / " t" ,
0 commit comments