-
Notifications
You must be signed in to change notification settings - Fork 14.9k
Open
Labels
clang:modulesC++20 modules and Clang Header ModulesC++20 modules and Clang Header Modules
Description
export module A;
built with -std=c++26 -fsyntax-only -include vector
fails to build due to:
<source>:1:8: error: module declaration must occur at the start of the translation unit
1 | export module A;
| ^
This is because -include vector
currently just injects #include "vector"
before the main file, which is invalid syntax for a module-file.
I think it would be most useful to instead inject it (along with most of the other stuff we inject) into the global module fragment, even if one doesn't exist. Given the preprocessor grammar, it is easy to detect this situation before calling clang::InitializePreprocessor
.
One way to do this, when we know it's a named module file, is to delay injecting these tokens until we encounter the first module declaration. If it's module;
, then just inject them as is, and if it's extern module A;
, then stick a module;
on front.
Metadata
Metadata
Assignees
Labels
clang:modulesC++20 modules and Clang Header ModulesC++20 modules and Clang Header Modules