[clang] [C++20][Modules] Implement P1857R3 Modules Dependency Discovery (PR #107168)
Hubert Tong via cfe-commits
cfe-commits at lists.llvm.org
Sun Oct 19 20:46:16 PDT 2025
================
@@ -142,6 +142,15 @@ void printDependencyDirectivesAsSource(
/// \returns true if any C++20 named modules related directive was found.
bool scanInputForCXX20ModulesUsage(StringRef Source);
+/// Scan an input source buffer, and check whether the input ssource is a
+/// preprocessed output.
+///
+/// \param Source The input source buffer.
+///
+/// \returns true if any '__preprocessed_module' or '__preprocessed_import'
+/// directive was found.
----------------
hubert-reinterpretcast wrote:
Checking for `__preprocessed_module` or `__preprocessed_import` may be a useful strategy, but it doesn't cover non-module cases that end up looking like module cases.
Consider this as a preprocessed file:
```cpp
typedef int module;
module x;
```
Compiling with `-xc++-cpp-output` should suppress `module` directive recognition. `__preprocessed_module` can either get the directive treatment or be accepted directly by phase 7 in a module declaration. In the latter case, `__preprocessed_module` will work even if there are preprocessing tokens on the same line that precede it.
An example of the `-x` option being consumed is in https://github.com/llvm/llvm-project/blob/3cf170c439086cf1465fd670f4fcbceefc522b92/clang/lib/Frontend/InitPreprocessor.cpp#L1654
https://github.com/llvm/llvm-project/pull/107168
More information about the cfe-commits
mailing list