else
Current.setType(TT_LineComment);
} else if (Current.is(tok::r_paren)) {
- if (rParenEndsCast(Current))
+ if (rParenEndsCast(Current)) {
Current.setType(TT_CastRParen);
+ assert(Current.MatchingParen);
+ Current.MatchingParen->setType(TT_Unknown);
+ }
if (Current.MatchingParen && Current.Next &&
!Current.Next->isBinaryOperator() &&
!Current.Next->isOneOf(tok::semi, tok::colon, tok::l_brace,
// Certain other tokens right before the parentheses are also signals that
// this cannot be a cast.
+ if (LeftOfParens->is(TT_TemplateCloser)) {
+ if (LeftOfParens->MatchingParen) {
+ auto *Prev = LeftOfParens->MatchingParen->getPreviousNonComment();
+ if (Prev &&
+ Prev->isOneOf(tok::kw_const_cast, tok::kw_dynamic_cast,
+ tok::kw_reinterpret_cast, tok::kw_static_cast))
+ // FIXME: Maybe we should handle identifiers ending with "_cast",
+ // e.g. any_cast?
+ return true;
+ }
+ return false;
+ }
if (LeftOfParens->isOneOf(tok::at, tok::r_square, TT_OverloadedOperator,
- TT_TemplateCloser, tok::ellipsis))
+ tok::ellipsis))
return false;
}
TEST_F(FormatTest, FormatsCasts) {
verifyFormat("Type *A = static_cast<Type *>(P);");
+ verifyFormat("static_cast<Type *>(P);");
+ verifyFormat("static_cast<Type &>(Fun)(Args);");
+ verifyFormat("static_cast<Type &>(*Fun)(Args);");
+ verifyFormat("a = static_cast<Type &>(*Fun)(Args);");
+ verifyFormat("const_cast<Type &>(*Fun)(Args);");
+ verifyFormat("dynamic_cast<Type &>(*Fun)(Args);");
+ verifyFormat("reinterpret_cast<Type &>(*Fun)(Args);");
verifyFormat("Type *A = (Type *)P;");
verifyFormat("Type *A = (vector<Type *, int *>)P;");
verifyFormat("int a = (int)(2.0f);");