[clang] [clang-format] Don't break module names (PR #193834)

Björn Schäpers via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 24 03:27:12 PDT 2026


HazardyKnusperkeks wrote:

> I think the culprit is that `isMemberAccess()` returns `true` on the dot in `export module a.b;`, so IMO the simplest solution is to annotate the dot in `consumeToken()`, similar to how the colon is annotated as `TT_ModulePartitionColon`:
> 
> ```diff
>      switch (bool IsIf = false; Tok->Tok.getKind()) {
>      case tok::plus:
>      case tok::minus:
>        if (!Prev && Line.MustBeDeclaration)
>          Tok->setType(TT_ObjCMethodSpecifier);
>        break;
> +    case tok::period:
> +      if ( ... ) // module/import declaration
> +        Tok->setType(TT_ModuleNameDot);
> +      break;
>      case tok::colon:
>        if (!Prev)
>          return false;
> ```
> 
> and exclude the new type:
> 
> ```diff
>    bool isMemberAccess() const {
>      return isOneOf(tok::arrow, tok::period, tok::arrowstar) &&
>             isNoneOf(TT_DesignatedInitializerPeriod, TT_TrailingReturnArrow,
> -                    TT_LambdaArrow, TT_LeadingJavaAnnotation);
> +                    TT_LambdaArrow, TT_LeadingJavaAnnotation, TT_ModuleNameDot);
>    }
> ```

We have the line type for import, I think we should use it. And as said in the other comment, we are not allowed to break anywhere on that line. Also already handled by the import line.

https://github.com/llvm/llvm-project/pull/193834


More information about the cfe-commits mailing list