From ff996645bfde8df72ebec94f7950deccd311177a Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Thu, 4 Dec 2014 08:57:27 +0000 Subject: [PATCH] clang-format: More restrictively classify import declarations. Before: import::SomeFunction(aaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaa); 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 | 3 ++- unittests/Format/FormatTest.cpp | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 9b215dcd47..9f692437ca 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -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; diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index ea5f67ca49..6481a3122f 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -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);"); } //===----------------------------------------------------------------------===// -- 2.40.0