mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-27 19:56:06 +00:00
[clang-format] Fix a bug that joins template closer and =
Also fixes the documentation for SpaceBeforeAssignmentOperators. See discussions at https://reviews.llvm.org/D66332 Differential Revision: https://reviews.llvm.org/D66384 llvm-svn: 369214
This commit is contained in:
parent
63b3c56fca
commit
37860d524e
@ -2051,7 +2051,7 @@ the configuration (without a prefix: ``Auto``).
|
||||
|
||||
true: false:
|
||||
int a = 5; vs. int a= 5;
|
||||
a += 42 a+=42;
|
||||
a += 42; a+= 42;
|
||||
|
||||
**SpaceBeforeCpp11BracedList** (``bool``)
|
||||
If ``true``, a space will be inserted before a C++11 braced list
|
||||
|
@ -1739,7 +1739,7 @@ struct FormatStyle {
|
||||
/// \code
|
||||
/// true: false:
|
||||
/// int a = 5; vs. int a= 5;
|
||||
/// a += 42 a+=42;
|
||||
/// a += 42; a+= 42;
|
||||
/// \endcode
|
||||
bool SpaceBeforeAssignmentOperators;
|
||||
|
||||
|
@ -2870,7 +2870,7 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
|
||||
Left.isOneOf(tok::arrow, tok::period, tok::arrowstar, tok::periodstar) ||
|
||||
(Right.is(tok::period) && Right.isNot(TT_DesignatedInitializerPeriod)))
|
||||
return false;
|
||||
if (!Style.SpaceBeforeAssignmentOperators &&
|
||||
if (!Style.SpaceBeforeAssignmentOperators && Left.isNot(TT_TemplateCloser) &&
|
||||
Right.getPrecedence() == prec::Assignment)
|
||||
return false;
|
||||
if (Style.Language == FormatStyle::LK_Java && Right.is(tok::coloncolon) &&
|
||||
|
@ -6620,8 +6620,15 @@ TEST_F(FormatTest, UnderstandsTemplateParameters) {
|
||||
|
||||
verifyFormat("A<A<int>> a;", getChromiumStyle(FormatStyle::LK_Cpp));
|
||||
|
||||
verifyFormat("int i = a<1> >> 1;");
|
||||
// template closer followed by a token that starts with > or =
|
||||
verifyFormat("bool b = a<1> > 1;");
|
||||
verifyFormat("bool b = a<1> >= 1;");
|
||||
verifyFormat("int i = a<1> >> 1;");
|
||||
FormatStyle Style = getLLVMStyle();
|
||||
Style.SpaceBeforeAssignmentOperators = false;
|
||||
verifyFormat("bool b= a<1> == 1;", Style);
|
||||
verifyFormat("a<int> = 1;", Style);
|
||||
verifyFormat("a<int> >>= 1;", Style);
|
||||
|
||||
verifyFormat("test >> a >> b;");
|
||||
verifyFormat("test << a >> b;");
|
||||
|
Loading…
x
Reference in New Issue
Block a user