[PATCH] D51036: clang-format: Fix formatting C++ namespaces with preceding 'inline' or 'export' specifier

Marco Elver via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 27 04:42:54 PDT 2018

melver added inline comments.

Comment at: lib/Format/Format.cpp:1312
       auto &Line = *AnnotatedLines[i];
       if (Line.startsWith(tok::kw_namespace) ||
+          Line.startsWith(tok::kw_inline, tok::kw_namespace) ||
owenpan wrote:
> sammccall wrote:
> > these 3 startswith checks appear 4 times now, you could pull out a helper function `startsWithNamespace` in FormatToken.h or something like that.
> > Up to you.
> I missed it. Good catch!
Added startsWithNamespace to TokenAnnotator.h.

Comment at: unittests/Format/FormatTest.cpp:7582
+  verifyFormat("export namespace Foo\n"
+               "{};",
sammccall wrote:
> you may want to add tests for other modules TS syntax (e.g. non-namespace export decls).
> It seems this works well today, but without tests it could regress.
I've added a couple for 'export class' with access specifiers. Otherwise, any other additions should probably be in future non-namespace related patches.

  rC Clang


More information about the cfe-commits mailing list