diff options
author | Paul Hoad <mydeveloperday@gmail.com> | 2019-10-04 14:16:59 +0000 |
---|---|---|
committer | Paul Hoad <mydeveloperday@gmail.com> | 2019-10-04 14:16:59 +0000 |
commit | ba12cec21f55cae6aaae0b57d08cab0de9358d51 (patch) | |
tree | de2195aa365975198c19ea6e3aef899089a1eb77 /clang/unittests/Format/FormatTest.cpp | |
parent | f44ca7f6eba468e146b0096a91dd9931b556aa86 (diff) | |
download | bcm5719-llvm-ba12cec21f55cae6aaae0b57d08cab0de9358d51.tar.gz bcm5719-llvm-ba12cec21f55cae6aaae0b57d08cab0de9358d51.zip |
[clang-format] [PR43531] clang-format damages "alternative representations" for operators
Summary:
https://bugs.llvm.org/show_bug.cgi?id=43531
Fix for clang-format incorrectly handles "alternative operators" as described by https://en.cppreference.com/w/cpp/language/operator_alternative
compl = ~
not = !
these are unary operators, and clang-format will remove the space between them and a numeric constant
this incorrectly formats the following code
```
int a compl 5;
int a not 5;
```
into:
```
int a compl5;
int a not5;
```
The code adds FIXME unit tests for "alternative token" representations for {} [] and # as defined by the same link, which would require a more detailed change to the FormatTokenLexer
Reviewers: klimek, reuk, owenpan, mitchell-stellar, STL_MSFT
Reviewed By: mitchell-stellar
Subscribers: cfe-commits
Tags: #clang-format, #clang-tools-extra, #clang
Differential Revision: https://reviews.llvm.org/D68332
llvm-svn: 373750
Diffstat (limited to 'clang/unittests/Format/FormatTest.cpp')
-rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index b770d0f26f8..14ac6f91372 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -14609,6 +14609,48 @@ TEST_F(FormatTest, AmbersandInLamda) { verifyFormat("auto lambda = [&a = a]() { a = 2; };", AlignStyle); } +TEST_F(FormatTest, AlternativeOperators) { + // Test case for ensuring alternate operators are not + // combined with their right most neighbour. + verifyFormat("int a and b;"); + verifyFormat("int a and_eq b;"); + verifyFormat("int a bitand b;"); + verifyFormat("int a bitor b;"); + verifyFormat("int a compl b;"); + verifyFormat("int a not b;"); + verifyFormat("int a not_eq b;"); + verifyFormat("int a or b;"); + verifyFormat("int a xor b;"); + verifyFormat("int a xor_eq b;"); + verifyFormat("return this not_eq bitand other;"); + verifyFormat("bool operator not_eq(const X bitand other)"); + + verifyFormat("int a and 5;"); + verifyFormat("int a and_eq 5;"); + verifyFormat("int a bitand 5;"); + verifyFormat("int a bitor 5;"); + verifyFormat("int a compl 5;"); + verifyFormat("int a not 5;"); + verifyFormat("int a not_eq 5;"); + verifyFormat("int a or 5;"); + verifyFormat("int a xor 5;"); + verifyFormat("int a xor_eq 5;"); + + verifyFormat("int a compl(5);"); + verifyFormat("int a not(5);"); + + /* FIXME handle alternate tokens + * https://en.cppreference.com/w/cpp/language/operator_alternative + // alternative tokens + verifyFormat("compl foo();"); // ~foo(); + verifyFormat("foo() <%%>;"); // foo(); + verifyFormat("void foo() <%%>;"); // void foo(){} + verifyFormat("int a <:1:>;"); // int a[1];[ + verifyFormat("%:define ABC abc"); // #define ABC abc + verifyFormat("%:%:"); // ## + */ +} + } // end namespace } // end namespace format } // end namespace clang |