Skip to content

Commit 296b9b1

Browse files
committed
[clang-format] Google Style: disable DerivePointerAlignment.
The Google C++ Style Guide is being changed to specify that spaces should go after the asterisk/ampersand, rather than permitting either before or after on a file-by-file basis. ObjC style is not being modified.
1 parent 2e67dcf commit 296b9b1

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

clang/lib/Format/Format.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1753,7 +1753,7 @@ FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language) {
17531753
GoogleStyle.AttributeMacros.push_back("absl_nullable");
17541754
GoogleStyle.AttributeMacros.push_back("absl_nullability_unknown");
17551755
GoogleStyle.BreakTemplateDeclarations = FormatStyle::BTDS_Yes;
1756-
GoogleStyle.DerivePointerAlignment = true;
1756+
GoogleStyle.DerivePointerAlignment = false;
17571757
GoogleStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Regroup;
17581758
GoogleStyle.IncludeStyle.IncludeCategories = {{"^<ext/.*\\.h>", 2, 0, false},
17591759
{"^<.*\\.h>", 1, 0, false},
@@ -1862,6 +1862,7 @@ FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language) {
18621862
} else if (Language == FormatStyle::LK_ObjC) {
18631863
GoogleStyle.AlwaysBreakBeforeMultilineStrings = false;
18641864
GoogleStyle.ColumnLimit = 100;
1865+
GoogleStyle.DerivePointerAlignment = true;
18651866
// "Regroup" doesn't work well for ObjC yet (main header heuristic,
18661867
// relationship between ObjC standard library headers and other heades,
18671868
// #imports, etc.)

clang/unittests/Format/FormatTest.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8571,10 +8571,10 @@ TEST_F(FormatTest, BreaksFunctionDeclarations) {
85718571
"operator<<(const SomeLooooooooooooooooooooooooogType &other);");
85728572
verifyGoogleFormat(
85738573
"SomeLoooooooooooooooooooooooooooooogType operator>>(\n"
8574-
" const SomeLooooooooogType &a, const SomeLooooooooogType &b);");
8574+
" const SomeLooooooooogType& a, const SomeLooooooooogType& b);");
85758575
verifyGoogleFormat(
85768576
"SomeLoooooooooooooooooooooooooooooogType operator<<(\n"
8577-
" const SomeLooooooooogType &a, const SomeLooooooooogType &b);");
8577+
" const SomeLooooooooogType& a, const SomeLooooooooogType& b);");
85788578

85798579
verifyFormat("void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
85808580
" int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = 1);");
@@ -8583,7 +8583,7 @@ TEST_F(FormatTest, BreaksFunctionDeclarations) {
85838583
verifyGoogleFormat(
85848584
"typename aaaaaaaaaa<aaaaaa>::aaaaaaaaaaa\n"
85858585
"aaaaaaaaaa<aaaaaa>::aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
8586-
" bool *aaaaaaaaaaaaaaaaaa, bool *aa) {}");
8586+
" bool* aaaaaaaaaaaaaaaaaa, bool* aa) {}");
85878587
verifyGoogleFormat("template <typename T>\n"
85888588
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
85898589
"aaaaaaaaaaaaaaaaaaaaaaa<T>::aaaaaaaaaaaaa(\n"
@@ -12287,6 +12287,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
1228712287
" aaaaaaaaaaaaaaaaaaaaaaaaaaaa, *aaaaaaaaaaaaaaaaaaaaaaaaaaaaa);");
1228812288

1228912289
verifyGoogleFormat("int const* a = &b;");
12290+
verifyFormat("int const* a = &b;", "int const *a = &b;", getGoogleStyle());
1229012291
verifyGoogleFormat("**outparam = 1;");
1229112292
verifyGoogleFormat("*outparam = a * b;");
1229212293
verifyGoogleFormat("int main(int argc, char** argv) {}");
@@ -12891,27 +12892,30 @@ TEST_F(FormatTest, UnderstandsEllipsis) {
1289112892
}
1289212893

1289312894
TEST_F(FormatTest, AdaptivelyFormatsPointersAndReferences) {
12895+
FormatStyle Style = getLLVMStyle();
12896+
Style.DerivePointerAlignment = true;
12897+
1289412898
verifyFormat("int *a;\n"
1289512899
"int *a;\n"
1289612900
"int *a;",
1289712901
"int *a;\n"
1289812902
"int* a;\n"
1289912903
"int *a;",
12900-
getGoogleStyle());
12904+
Style);
1290112905
verifyFormat("int* a;\n"
1290212906
"int* a;\n"
1290312907
"int* a;",
1290412908
"int* a;\n"
1290512909
"int* a;\n"
1290612910
"int *a;",
12907-
getGoogleStyle());
12911+
Style);
1290812912
verifyFormat("int *a;\n"
1290912913
"int *a;\n"
1291012914
"int *a;",
1291112915
"int *a;\n"
1291212916
"int * a;\n"
1291312917
"int * a;",
12914-
getGoogleStyle());
12918+
Style);
1291512919
verifyFormat("auto x = [] {\n"
1291612920
" int *a;\n"
1291712921
" int *a;\n"
@@ -12920,7 +12924,7 @@ TEST_F(FormatTest, AdaptivelyFormatsPointersAndReferences) {
1292012924
"auto x=[]{int *a;\n"
1292112925
"int * a;\n"
1292212926
"int * a;};",
12923-
getGoogleStyle());
12927+
Style);
1292412928
}
1292512929

1292612930
TEST_F(FormatTest, UnderstandsRvalueReferences) {
@@ -13056,7 +13060,7 @@ TEST_F(FormatTest, FormatsCasts) {
1305613060
verifyFormat("virtual void foo(char &) const;");
1305713061
verifyFormat("virtual void foo(int *a, char *) const;");
1305813062
verifyFormat("int a = sizeof(int *) + b;");
13059-
verifyGoogleFormat("int a = alignof(int *) + b;");
13063+
verifyGoogleFormat("int a = alignof(int*) + b;");
1306013064
verifyFormat("bool b = f(g<int>) && c;");
1306113065
verifyFormat("typedef void (*f)(int i) func;");
1306213066
verifyFormat("void operator++(int) noexcept;");
@@ -25419,7 +25423,7 @@ TEST_F(FormatTest, AtomicQualifier) {
2541925423
verifyFormat("struct foo {\n"
2542025424
" int a1;\n"
2542125425
" _Atomic(a) a2;\n"
25422-
" _Atomic(_Atomic(int) *const) a3;\n"
25426+
" _Atomic(_Atomic(int)* const) a3;\n"
2542325427
"};",
2542425428
Google);
2542525429
verifyFormat("_Atomic(uint64_t) a;");

0 commit comments

Comments
 (0)