Skip to content

Commit fe78a9a

Browse files
committed
[NFC] [clangd] [C++20 Modules] Add a warning if clangd detected multiple
source declares the same module Now clangd assumes no duplicated module declared by different source file in a sinlge project. But in practice, it may not be the case. Although we can't fix it now, emitting a warning is helpful for users to understand what's going on.
1 parent 9091108 commit fe78a9a

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

clang-tools-extra/clangd/ScanningProjectModules.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,17 @@ ModuleDependencyScanner::scan(PathRef FilePath,
122122
ModuleDependencyInfo Result;
123123

124124
if (ScanningResult->Provides) {
125-
ModuleNameToSource[ScanningResult->Provides->ModuleName] = FilePath;
126125
Result.ModuleName = ScanningResult->Provides->ModuleName;
126+
127+
auto [Iter, Inserted] = ModuleNameToSource.try_emplace(
128+
ScanningResult->Provides->ModuleName, FilePath);
129+
130+
if (!Inserted && Iter->second != FilePath) {
131+
elog("Detected multiple source files ({0}, {1}) declaring the same "
132+
"module: '{2}'. "
133+
"Now clangd may find the wrong source in such case.",
134+
Iter->second, FilePath, ScanningResult->Provides->ModuleName);
135+
}
127136
}
128137

129138
for (auto &Required : ScanningResult->Requires)

0 commit comments

Comments
 (0)