}
}
if (Style.DerivePointerAlignment) {
- Style.PointerAlignment = countVariableAlignments(AnnotatedLines) <= 0
- ? FormatStyle::PAS_Left
- : FormatStyle::PAS_Right;
+ const auto NetRightCount = countVariableAlignments(AnnotatedLines);
+ if (NetRightCount > 0)
+ Style.PointerAlignment = FormatStyle::PAS_Right;
+ else if (NetRightCount < 0)
+ Style.PointerAlignment = FormatStyle::PAS_Left;
Style.ReferenceAlignment = FormatStyle::RAS_Pointer;
}
if (Style.Standard == FormatStyle::LS_Auto) {
format(Prefix + "int* x;", DerivePointerAlignment));
}
+TEST_F(FormatTest, PointerAlignmentFallback) {
+ FormatStyle Style = getLLVMStyle();
+ Style.DerivePointerAlignment = true;
+
+ const StringRef Code("int* p;\n"
+ "int *q;\n"
+ "int * r;");
+
+ EXPECT_EQ(Style.PointerAlignment, FormatStyle::PAS_Right);
+ verifyFormat("int *p;\n"
+ "int *q;\n"
+ "int *r;",
+ Code, Style);
+
+ Style.PointerAlignment = FormatStyle::PAS_Left;
+ verifyFormat("int* p;\n"
+ "int* q;\n"
+ "int* r;",
+ Code, Style);
+
+ Style.PointerAlignment = FormatStyle::PAS_Middle;
+ verifyFormat("int * p;\n"
+ "int * q;\n"
+ "int * r;",
+ Code, Style);
+}
+
TEST_F(FormatTest, UnderstandsNewAndDelete) {
verifyFormat("void f() {\n"
" A *a = new A;\n"