From: Daniel Jasper Date: Mon, 13 Jun 2016 07:49:28 +0000 (+0000) Subject: clang-format: Don't merge const and &, e.g. in function ref qualifiers. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ae85d31708ebe98f3b4b87847e4670617e3d9218;p=clang clang-format: Don't merge const and &, e.g. in function ref qualifiers. 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@272537 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 1f1a32a2b2..8a36aca97e 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -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))); diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 7e3b4ce357..d82770ba68 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -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; @@ -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;