Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -1915,6 +1915,13 @@ if (Tok.Next->isOneOf(tok::identifier, tok::kw_this)) return true; + if (Tok.Next->is(tok::l_paren) && + !(Tok.Previous && Tok.Previous->is(tok::identifier) && + Tok.Previous->Previous && + Tok.Previous->Previous->isOneOf(tok::arrowstar, tok::arrow, + tok::star))) + return true; + if (!Tok.Next->Next) return false; Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -11989,6 +11989,20 @@ " do_something((int) i);\n" "} while (something( ));", Spaces); + + verifyFormat("size_t idx = (size_t) (ptr - ((char *) file));", Spaces); + verifyFormat("size_t idx = (size_t) a;", Spaces); + verifyFormat("size_t idx = (size_t) (a - 1);", Spaces); + verifyFormat("size_t idx = (a->*foo)(a - 1);", Spaces); + verifyFormat("size_t idx = (a->foo)(a - 1);", Spaces); + verifyFormat("size_t idx = (*foo)(a - 1);", Spaces); + Spaces.SpaceAfterCStyleCast = false; + verifyFormat("size_t idx = (size_t)(ptr - ((char *)file));", Spaces); + verifyFormat("size_t idx = (size_t)a;", Spaces); + verifyFormat("size_t idx = (size_t)(a - 1);", Spaces); + verifyFormat("size_t idx = (a->*foo)(a - 1);", Spaces); + verifyFormat("size_t idx = (a->foo)(a - 1);", Spaces); + verifyFormat("size_t idx = (*foo)(a - 1);", Spaces); } TEST_F(FormatTest, ConfigurableSpacesInSquareBrackets) {