[clang] 2d23175 - [clang-format] Fix a bug with C++ `export import <Foo/Bar>`

via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 28 19:10:23 PDT 2022


Author: owenca
Date: 2022-09-28T19:10:12-07:00
New Revision: 2d23175fae989f90a09e556542309cd5a903e7cc

URL: https://github.com/llvm/llvm-project/commit/2d23175fae989f90a09e556542309cd5a903e7cc
DIFF: https://github.com/llvm/llvm-project/commit/2d23175fae989f90a09e556542309cd5a903e7cc.diff

LOG: [clang-format] Fix a bug with C++ `export import <Foo/Bar>`

Fixes #57798.

Differential Revision: https://reviews.llvm.org/D134700

Added: 
    

Modified: 
    clang/lib/Format/UnwrappedLineParser.cpp
    clang/unittests/Format/FormatTest.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index a5dbd43cdf264..ead3f7f1c7d46 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -1634,10 +1634,18 @@ void UnwrappedLineParser::parseStructuralElement(
       parseJavaScriptEs6ImportExport();
       return;
     }
-    if (!Style.isCpp())
-      break;
-    // Handle C++ "(inline|export) namespace".
-    [[fallthrough]];
+    if (Style.isCpp()) {
+      nextToken();
+      if (FormatTok->is(Keywords.kw_import)) {
+        parseModuleImport();
+        return;
+      }
+      if (FormatTok->is(tok::kw_namespace)) {
+        parseNamespace();
+        return;
+      }
+    }
+    break;
   case tok::kw_inline:
     nextToken();
     if (FormatTok->is(tok::kw_namespace)) {

diff  --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 4c11104343a4d..9a1396b196ffe 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -25140,6 +25140,7 @@ TEST_F(FormatTest, Cpp20ModulesSupport) {
   verifyFormat("export module foo.bar;", Style);
   verifyFormat("export module foo.bar:baz;", Style);
   verifyFormat("export import <string_view>;", Style);
+  verifyFormat("export import <Foo/Bar>;", Style);
 
   verifyFormat("export type_name var;", Style);
   verifyFormat("template <class T> export using A = B<T>;", Style);


        


More information about the cfe-commits mailing list