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

via cfe-commits cfe-commits at lists.llvm.org
Sun May 3 20:08:39 PDT 2026


=?utf-8?q?Bj=C3=B6rn_Sch=C3=A4pers?= <bjoern at hazardy.de>,
=?utf-8?q?Bj=C3=B6rn_Sch=C3=A4pers?= <bjoern at hazardy.de>,
=?utf-8?q?Bj=C3=B6rn_Sch=C3=A4pers?= <bjoern at hazardy.de>,
=?utf-8?q?Bj=C3=B6rn_Sch=C3=A4pers?= <bjoern at hazardy.de>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/193834 at github.com>


================
@@ -116,6 +117,27 @@ class AnnotatedLine {
     return First && First->is(tok::comment) && !First->getNextNonComment();
   }
 
+  bool isCppModuleLine(const AdditionalKeywords &Keywords) const {
+    if (!First)
+      return false;
+    if (startsWith(tok::kw_export, Keywords.kw_module) ||
+        startsWith(tok::kw_export, Keywords.kw_import)) {
+      return true;
+    }
+
+    if (First->isNoneOf(Keywords.kw_module, Keywords.kw_import))
+      return false;
+
+    // Pre-C++20 code using import (or module) as identifier e.g. for a
+    // namespace.
+    if (auto Next = First->getNextNonComment()) {
+      return !Next->isMemberAccess() &&
+             Next->isNoneOf(tok::coloncolon, tok::star);
+    }
----------------
owenca wrote:

But it should return `false` for the following lines:
```c++
module(0);
import++;
```

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


More information about the cfe-commits mailing list