Skip to content

Commit

Permalink
clang-format: Don't merge const and &, e.g. in function ref qualifiers.
Browse files Browse the repository at this point in the history
Before (when aligning & to the right):
  SomeType MemberFunction(const Deleted &) const&;

After:
  SomeType MemberFunction(const Deleted &) const &;

This also applies to variable declarations, e.g.:
  int const * a;

However, this form is very uncommon (most people would write
"const int* a" instead) and contracting to "const*" might actually send
the wrong signal of what the const binds to.

llvm-svn: 272537
  • Loading branch information
djasper-gh committed Jun 13, 2016
1 parent 594be2f commit 43e4d3a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion clang/lib/Format/TokenAnnotator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1993,7 +1993,7 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
return false;
if (Right.is(TT_PointerOrReference))
return (Left.is(tok::r_paren) && Line.MightBeFunctionDecl) ||
(Left.Tok.isLiteral() ||
(Left.Tok.isLiteral() || Left.is(tok::kw_const) ||
(!Left.isOneOf(TT_PointerOrReference, tok::l_paren) &&
(Style.PointerAlignment != FormatStyle::PAS_Left ||
Line.IsMultiVariableDeclStmt)));
Expand Down
2 changes: 2 additions & 0 deletions clang/unittests/Format/FormatTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5627,6 +5627,7 @@ TEST_F(FormatTest, UnderstandsFunctionRefQualification) {
verifyFormat("SomeType MemberFunction(const Deleted &) && {}");
verifyFormat("SomeType MemberFunction(const Deleted &) && final {}");
verifyFormat("SomeType MemberFunction(const Deleted &) && override {}");
verifyFormat("SomeType MemberFunction(const Deleted &) const &;");

FormatStyle AlignLeft = getLLVMStyle();
AlignLeft.PointerAlignment = FormatStyle::PAS_Left;
Expand All @@ -5640,6 +5641,7 @@ TEST_F(FormatTest, UnderstandsFunctionRefQualification) {
verifyFormat("auto Function(T... t) & -> void {}", AlignLeft);
verifyFormat("auto Function(T) & -> void {}", AlignLeft);
verifyFormat("auto Function(T) & -> void;", AlignLeft);
verifyFormat("SomeType MemberFunction(const Deleted&) const &;", AlignLeft);

FormatStyle Spaces = getLLVMStyle();
Spaces.SpacesInCStyleCastParentheses = true;
Expand Down

0 comments on commit 43e4d3a

Please sign in to comment.