for (int i = 1, e = Line.Tokens.size(); i != e; ++i) {
TokenAnnotation &Annotation = Annotations[i];
- Annotation.CanBreakBefore =
- canBreakBetween(Line.Tokens[i - 1], Line.Tokens[i]);
+ Annotation.CanBreakBefore = canBreakBefore(i);
if (Annotation.Type == TokenAnnotation::TT_CtorInitializerColon) {
Annotation.MustBreakBefore = true;
return true;
}
- bool canBreakBetween(const FormatToken &Left, const FormatToken &Right) {
+ bool canBreakBefore(unsigned i) {
+ if (Annotations[i - 1].Type == TokenAnnotation::TT_PointerOrReference ||
+ Annotations[i].Type == TokenAnnotation::TT_ConditionalExpr) {
+ return false;
+ }
+ const FormatToken &Left = Line.Tokens[i - 1];
+ const FormatToken &Right = Line.Tokens[i];
if (Right.Tok.is(tok::r_paren) || Right.Tok.is(tok::l_brace) ||
Right.Tok.is(tok::comment) || Right.Tok.is(tok::greater))
return false;
verifyGoogleFormat("A<int**, int**> a;");
}
+TEST_F(FormatTest, DoesNotBreakBeforePointerOrReference) {
+ verifyFormat(
+ "int *someFunction(int LoooooooooooooooongParam1,\n"
+ " int LoooooooooooooooongParam2) {\n}");
+ verifyFormat(
+ "TypeSpecDecl *TypeSpecDecl::Create(ASTContext &C, DeclContext *DC,\n"
+ " SourceLocation L, IdentifierIn *II,\n"
+ " Type *T) {\n}");
+}
+
TEST_F(FormatTest, LineStartsWithSpecialCharacter) {
verifyFormat("(a)->b();");
verifyFormat("--a;");