There are other things which are permitted which would also invalidate your assumptions. For example, imports in headers, and the fact that import locations aren't restricted within non-module units. Also I believe imports are allowed at the start of the private module fragment too.
It does seem that there was a lot of iteration on this and I find it a little confusing where we've ended up. I don't see how the scanning requirements are all that much below a full preprocessing, but perhaps I'm missing something significant. Yet we've also ended up with constraints (around module directives in particular) that cause real problems for transitioning code to modules in a gradual/toggleable way, where it's no longer entirely clear if the original reasoning for those constraints still applies.
I don't have conclusive standard text confirming this off-hand, but yes I believe so. Pretty sure what you refer to is talking about the state of the translation unit after preprocessing - after all, the concept of a 'declaration' isn't even meaningful at the point that #includes are processed.
Honestly, cpp reference (which is I guess the source of your quote) just doesn't suffice for the details, you really have to study the standard. Equivalent in this case being https://eel.is/c++draft/module.import
View all comments
Show parent comment
2
u/kamrann_ Mar 11 '26
There are other things which are permitted which would also invalidate your assumptions. For example, imports in headers, and the fact that import locations aren't restricted within non-module units. Also I believe imports are allowed at the start of the private module fragment too.
It does seem that there was a lot of iteration on this and I find it a little confusing where we've ended up. I don't see how the scanning requirements are all that much below a full preprocessing, but perhaps I'm missing something significant. Yet we've also ended up with constraints (around module directives in particular) that cause real problems for transitioning code to modules in a gradual/toggleable way, where it's no longer entirely clear if the original reasoning for those constraints still applies.