From: Daniel Jasper Date: Wed, 17 Jul 2013 20:25:02 +0000 (+0000) Subject: clang-format: Add space in corner case. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e0fa4c55a4bc6d2bbe0d9d657287c037158d5357;p=clang clang-format: Add space in corner case. Before: SomeType s __attribute__((unused))(InitValue); After: SomeType s __attribute__((unused)) (InitValue); git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@186535 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 021fd2488b..97be71c277 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -1151,6 +1151,10 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line, if (Left.is(tok::l_paren)) return false; if (Right.is(tok::l_paren)) { + if (Left.is(tok::r_paren) && Left.MatchingParen && + Left.MatchingParen->Previous && + Left.MatchingParen->Previous->is(tok::kw___attribute)) + return true; return Line.Type == LT_ObjCDecl || Left.isOneOf(tok::kw_if, tok::kw_for, tok::kw_while, tok::kw_switch, tok::kw_return, tok::kw_catch, tok::kw_new, diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 353fcc7d0b..05119f37cb 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -3546,6 +3546,10 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) { verifyFormat("delete *x;", PointerLeft); } +TEST_F(FormatTest, UnderstandsAttributes) { + verifyFormat("SomeType s __attribute__((unused)) (InitValue);"); +} + TEST_F(FormatTest, UnderstandsEllipsis) { verifyFormat("int printf(const char *fmt, ...);"); verifyFormat("template void Foo(Ts... ts) { Foo(ts...); }");