From afbad5d1371216aa534c89c72c8f17481b6771a7 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Mon, 26 Oct 2015 12:08:47 +0000 Subject: [PATCH] clang-format: Fix false positive in cast detection. Before (with spaces in parentheses): void inFunction() { std::function fct; } After: void inFunction() { std::function fct; } git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@251284 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/TokenAnnotator.cpp | 3 ++- unittests/Format/FormatTest.cpp | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index fbd7fe4f6f..8ec11ced1d 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -1086,7 +1086,8 @@ private: Tok.Previous->isOneOf(TT_PointerOrReference, TT_TemplateCloser) || Tok.Previous->isSimpleTypeSpecifier(); bool ParensCouldEndDecl = - Tok.Next && Tok.Next->isOneOf(tok::equal, tok::semi, tok::l_brace); + Tok.Next && + Tok.Next->isOneOf(tok::equal, tok::semi, tok::l_brace, tok::greater); bool IsSizeOfOrAlignOf = LeftOfParens && LeftOfParens->isOneOf(tok::kw_sizeof, tok::kw_alignof); if (ParensAreType && !ParensCouldEndDecl && !IsSizeOfOrAlignOf && diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 06970bac0a..3653bdb388 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -8398,6 +8398,8 @@ TEST_F(FormatTest, ConfigurableSpacesInParentheses) { verifyFormat("call( x, y, z );", Spaces); verifyFormat("call();", Spaces); verifyFormat("std::function callback;", Spaces); + verifyFormat("void inFunction() { std::function fct; }", + Spaces); verifyFormat("while ( (bool)1 )\n" " continue;", Spaces); @@ -10633,6 +10635,9 @@ TEST_F(FormatTest, SpacesInAngles) { verifyFormat("f< int, float >();", Spaces); verifyFormat("template <> g() {}", Spaces); verifyFormat("template < std::vector< int > > f() {}", Spaces); + verifyFormat("std::function< void(int, int) > fct;", Spaces); + verifyFormat("void inFunction() { std::function< void(int, int) > fct; }", + Spaces); Spaces.Standard = FormatStyle::LS_Cpp03; Spaces.SpacesInAngles = true; -- 2.40.0