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

Fixes #57798.

Differential Revision: https://reviews.llvm.org/D134700
This commit is contained in:
owenca 2022-09-26 22:34:53 -07:00
parent adf4eda004
commit 2d23175fae
2 changed files with 13 additions and 4 deletions

View File

@ -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)) {

View File

@ -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);