Skip to content

Commit 252d6bd

Browse files
jyknightmahesh-attarde
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.
1 parent 90e4d8d commit 252d6bd

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
@@ -1754,7 +1754,6 @@ FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language) {
17541754
GoogleStyle.AttributeMacros.push_back("absl_nullable");
17551755
GoogleStyle.AttributeMacros.push_back("absl_nullability_unknown");
17561756
GoogleStyle.BreakTemplateDeclarations = FormatStyle::BTDS_Yes;
1757-
GoogleStyle.DerivePointerAlignment = true;
17581757
GoogleStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Regroup;
17591758
GoogleStyle.IncludeStyle.IncludeCategories = {{"^<ext/.*\\.h>", 2, 0, false},
17601759
{"^<.*\\.h>", 1, 0, false},
@@ -1863,6 +1862,7 @@ FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language) {
18631862
} else if (Language == FormatStyle::LK_ObjC) {
18641863
GoogleStyle.AlwaysBreakBeforeMultilineStrings = false;
18651864
GoogleStyle.ColumnLimit = 100;
1865+
GoogleStyle.DerivePointerAlignment = true;
18661866
// "Regroup" doesn't work well for ObjC yet (main header heuristic,
18671867
// relationship between ObjC standard library headers and other heades,
18681868
// #imports, etc.)

clang/unittests/Format/FormatTest.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8593,10 +8593,10 @@ TEST_F(FormatTest, BreaksFunctionDeclarations) {
85938593
"operator<<(const SomeLooooooooooooooooooooooooogType &other);");
85948594
verifyGoogleFormat(
85958595
"SomeLoooooooooooooooooooooooooooooogType operator>>(\n"
8596-
" const SomeLooooooooogType &a, const SomeLooooooooogType &b);");
8596+
" const SomeLooooooooogType& a, const SomeLooooooooogType& b);");
85978597
verifyGoogleFormat(
85988598
"SomeLoooooooooooooooooooooooooooooogType operator<<(\n"
8599-
" const SomeLooooooooogType &a, const SomeLooooooooogType &b);");
8599+
" const SomeLooooooooogType& a, const SomeLooooooooogType& b);");
86008600

86018601
verifyFormat("void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
86028602
" int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = 1);");
@@ -8605,7 +8605,7 @@ TEST_F(FormatTest, BreaksFunctionDeclarations) {
86058605
verifyGoogleFormat(
86068606
"typename aaaaaaaaaa<aaaaaa>::aaaaaaaaaaa\n"
86078607
"aaaaaaaaaa<aaaaaa>::aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
8608-
" bool *aaaaaaaaaaaaaaaaaa, bool *aa) {}");
8608+
" bool* aaaaaaaaaaaaaaaaaa, bool* aa) {}");
86098609
verifyGoogleFormat("template <typename T>\n"
86108610
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
86118611
"aaaaaaaaaaaaaaaaaaaaaaa<T>::aaaaaaaaaaaaa(\n"
@@ -12915,27 +12915,31 @@ TEST_F(FormatTest, UnderstandsEllipsis) {
1291512915
}
1291612916

1291712917
TEST_F(FormatTest, AdaptivelyFormatsPointersAndReferences) {
12918+
auto Style = getGoogleStyle();
12919+
EXPECT_FALSE(Style.DerivePointerAlignment);
12920+
Style.DerivePointerAlignment = true;
12921+
1291812922
verifyFormat("int *a;\n"
1291912923
"int *a;\n"
1292012924
"int *a;",
1292112925
"int *a;\n"
1292212926
"int* a;\n"
1292312927
"int *a;",
12924-
getGoogleStyle());
12928+
Style);
1292512929
verifyFormat("int* a;\n"
1292612930
"int* a;\n"
1292712931
"int* a;",
1292812932
"int* a;\n"
1292912933
"int* a;\n"
1293012934
"int *a;",
12931-
getGoogleStyle());
12935+
Style);
1293212936
verifyFormat("int *a;\n"
1293312937
"int *a;\n"
1293412938
"int *a;",
1293512939
"int *a;\n"
1293612940
"int * a;\n"
1293712941
"int * a;",
12938-
getGoogleStyle());
12942+
Style);
1293912943
verifyFormat("auto x = [] {\n"
1294012944
" int *a;\n"
1294112945
" int *a;\n"
@@ -12944,7 +12948,7 @@ TEST_F(FormatTest, AdaptivelyFormatsPointersAndReferences) {
1294412948
"auto x=[]{int *a;\n"
1294512949
"int * a;\n"
1294612950
"int * a;};",
12947-
getGoogleStyle());
12951+
Style);
1294812952
}
1294912953

1295012954
TEST_F(FormatTest, UnderstandsRvalueReferences) {
@@ -13080,7 +13084,7 @@ TEST_F(FormatTest, FormatsCasts) {
1308013084
verifyFormat("virtual void foo(char &) const;");
1308113085
verifyFormat("virtual void foo(int *a, char *) const;");
1308213086
verifyFormat("int a = sizeof(int *) + b;");
13083-
verifyGoogleFormat("int a = alignof(int *) + b;");
13087+
verifyGoogleFormat("int a = alignof(int*) + b;");
1308413088
verifyFormat("bool b = f(g<int>) && c;");
1308513089
verifyFormat("typedef void (*f)(int i) func;");
1308613090
verifyFormat("void operator++(int) noexcept;");
@@ -25449,7 +25453,7 @@ TEST_F(FormatTest, AtomicQualifier) {
2544925453
verifyFormat("struct foo {\n"
2545025454
" int a1;\n"
2545125455
" _Atomic(a) a2;\n"
25452-
" _Atomic(_Atomic(int) *const) a3;\n"
25456+
" _Atomic(_Atomic(int)* const) a3;\n"
2545325457
"};",
2545425458
Google);
2545525459
verifyFormat("_Atomic(uint64_t) a;");

0 commit comments

Comments
 (0)