Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion clang/lib/Sema/SemaModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,12 @@ void Sema::BuildModuleInclude(SourceLocation DirectiveLoc, Module *Mod) {
Module *ThisModule = PP.getHeaderSearchInfo().lookupModule(
getLangOpts().CurrentModule, DirectiveLoc, false, false);
(void)ThisModule;
assert(ThisModule && "was expecting a module if building one");
// For named modules, the current module name is not known while parsing the
// global module fragment and lookupModule may return null.
assert((getLangOpts().getCompilingModule() ==
LangOptionsBase::CMK_ModuleInterface ||
ThisModule) &&
"was expecting a module if building a Clang module");
}
}

Expand Down
24 changes: 24 additions & 0 deletions clang/test/Modules/named-module-with-fmodules.cppm
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Checks that Clang modules can be imported from within the global module
// fragment of a named module interface unit.
// Fixes #159768.

// RUN: rm -rf %t
// RUN: mkdir -p %t
// RUN: split-file %s %t

// RUN: %clang -std=c++23 -fmodules -fmodule-map-file=%t/module.modulemap \
// RUN: --precompile %t/A.cppm -o %t/A.pcm

//--- module.modulemap
module foo { header "foo.h" }

//--- foo.h
// empty

//--- A.cppm
module;
#include "foo.h"
export module A;

export auto A() -> int { return 42; }