[clang] [clang-format] Don't break module names (PR #193834)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Apr 25 22:19:07 PDT 2026
owenca wrote:
> > > We have the line type for import, I think we should use it.
> >
> >
> > Looks like `LT_ImportStatement` is for Objective-C `#import` directive and JavaScript `import` statement.
>
> Yes, because C++ didn't have those back in the days. Now we have.
Looks like it was meant for Objective-C (but missed `@import`?) and then extended to JavaScript or vice versa. (It's also used for Java import statements.) Then C++ `export import` and `export module` were added. However, they all have very different syntax.
`UnwrappedLineParser::parseModuleImport()` is problematic likely because it was also meant for one language and later patched to support other languages. So I really think we should restart on a clean slate for C++ module/import declarations by adding two functions (in separate patches if desired) `parseModuleDeclaration()` and `parseImportDeclaration()` that parse the unwrapped line according to the [syntax](https://cppreference.com/cpp/language/modules#Syntax). If the line is parsed successfully, it is marked as `IsModuleOrImportDecl` for the token annotator to process as outlined above.
> I can agree that the question if a line break is allowed at all (but maybe not on all places?) is open to debate. As far as I understand the draft the C++ standard does not impose that limitation, but reality is that GCC doesn't accept it, and clang in recent versions too. So we have the possibility to break real world usage.
I'm now inclined to support *not* splitting the lines.
> But if we decide a line break is not allowed, I think the import statement type is really neat, because it already does what we need and we don't need all the state checking if breaking or not, it always goes the route of no breaking.
I'm not sure if it should always go the route of no breaking because `LT_ImportStatement` is also used for `LK_Java` and `LK_JavaScript`, whose import statements are not required to stay on one line AFAIK.
https://github.com/llvm/llvm-project/pull/193834
More information about the cfe-commits
mailing list