Skip to content

Commit c7ac782

Browse files
jyknighttru
authored andcommitted
[clang-format] Google Style: disable DerivePointerAlignment. (llvm#149602)
The [Google C++ Style Guide](https://google.github.io/styleguide/cppguide.html#Pointer_and_Reference_Expressions) 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. The new requirement is: > When referring to a pointer or reference (variable declarations or > definitions, arguments, return types, template parameters, etc.), > you must not place a space before the asterisk/ampersand. Use a > space to separate the type from the declared name (if present). The [Google ObjC style](https://google.github.io/styleguide/objcguide.html) is silent on this matter, but the de-facto style is not being modified at this time. So, keep DerivePointerAlignment enabled for ObjC language mode. (cherry picked from commit 9281797)
1 parent ca8b2f3 commit c7ac782

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

clang/lib/Format/Format.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1749,7 +1749,6 @@ FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language) {
17491749
GoogleStyle.AttributeMacros.push_back("absl_nullable");
17501750
GoogleStyle.AttributeMacros.push_back("absl_nullability_unknown");
17511751
GoogleStyle.BreakTemplateDeclarations = FormatStyle::BTDS_Yes;
1752-
GoogleStyle.DerivePointerAlignment = true;
17531752
GoogleStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Regroup;
17541753
GoogleStyle.IncludeStyle.IncludeCategories = {{"^<ext/.*\\.h>", 2, 0, false},
17551754
{"^<.*\\.h>", 1, 0, false},
@@ -1858,6 +1857,7 @@ FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language) {
18581857
} else if (Language == FormatStyle::LK_ObjC) {
18591858
GoogleStyle.AlwaysBreakBeforeMultilineStrings = false;
18601859
GoogleStyle.ColumnLimit = 100;
1860+
GoogleStyle.DerivePointerAlignment = true;
18611861
// "Regroup" doesn't work well for ObjC yet (main header heuristic,
18621862
// relationship between ObjC standard library headers and other heades,
18631863
// #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"
@@ -12891,27 +12891,31 @@ TEST_F(FormatTest, UnderstandsEllipsis) {
1289112891
}
1289212892

1289312893
TEST_F(FormatTest, AdaptivelyFormatsPointersAndReferences) {
12894+
auto Style = getGoogleStyle();
12895+
EXPECT_FALSE(Style.DerivePointerAlignment);
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;");
@@ -25425,7 +25429,7 @@ TEST_F(FormatTest, AtomicQualifier) {
2542525429
verifyFormat("struct foo {\n"
2542625430
" int a1;\n"
2542725431
" _Atomic(a) a2;\n"
25428-
" _Atomic(_Atomic(int) *const) a3;\n"
25432+
" _Atomic(_Atomic(int)* const) a3;\n"
2542925433
"};",
2543025434
Google);
2543125435
verifyFormat("_Atomic(uint64_t) a;");

0 commit comments

Comments
 (0)