]> granicus.if.org Git - clang/commitdiff
clang-format: More restrictively classify import declarations.
authorDaniel Jasper <djasper@google.com>
Thu, 4 Dec 2014 08:57:27 +0000 (08:57 +0000)
committerDaniel Jasper <djasper@google.com>
Thu, 4 Dec 2014 08:57:27 +0000 (08:57 +0000)
Before:
  import::SomeFunction(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);

After:
  import::SomeFunction(aaaaaaaaaaaaaaaaaaaaaaaaaaa,
                       aaaaaaaaaaaaaaaaaaaaaaaaaaaaa);

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@223345 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTest.cpp

index 9b215dcd473bc7783f6919f8bd31a66816ee5506..9f692437cad4c67f4532d92e7e4117bc84adf28a 100644 (file)
@@ -615,7 +615,8 @@ public:
     if ((Style.Language == FormatStyle::LK_Java &&
          CurrentToken->is(Keywords.kw_package)) ||
         (Info && Info->getPPKeywordID() == tok::pp_import &&
-         CurrentToken->Next)) {
+         CurrentToken->Next &&
+         CurrentToken->Next->isOneOf(tok::string_literal, tok::identifier))) {
       next();
       parseIncludeDirective();
       return LT_ImportStatement;
index ea5f67ca49d6483d3b6a8cec10e0659290af0a67..6481a3122f62771af797da9ab1a84f20a9d25a9a 100644 (file)
@@ -5611,6 +5611,10 @@ TEST_F(FormatTest, HandlesIncludeDirectives) {
   Style.AlwaysBreakBeforeMultilineStrings = true;
   Style.ColumnLimit = 0;
   verifyFormat("#import \"abc.h\"", Style);
+
+  // But 'import' might also be a regular C++ namespace.
+  verifyFormat("import::SomeFunction(aaaaaaaaaaaaaaaaaaaaaaaaaaa,\n"
+               "                     aaaaaaaaaaaaaaaaaaaaaaaaaaaaa);");
 }
 
 //===----------------------------------------------------------------------===//