diff options
author | Manuel Klimek <klimek@google.com> | 2018-04-11 14:51:54 +0000 |
---|---|---|
committer | Manuel Klimek <klimek@google.com> | 2018-04-11 14:51:54 +0000 |
commit | d0f3fe5563a96d0db9e7fc27c54a3a0b1083c715 (patch) | |
tree | 35c44122039db2a31f30e18b63d877664c03f1c7 /clang/unittests/Format/FormatTest.cpp | |
parent | 9381ae9791d57dd09fa10c22d52a17ca2bbcd4b2 (diff) | |
download | bcm5719-llvm-d0f3fe5563a96d0db9e7fc27c54a3a0b1083c715.tar.gz bcm5719-llvm-d0f3fe5563a96d0db9e7fc27c54a3a0b1083c715.zip |
Fix bugs around handling C++11 attributes.
Previously, we would format:
int a() { ... }
[[unused]] int b() { ... }
as...
int a() {} [[unused] int b() {}
Now we correctly format each on its own line.
Similarly, we would detect:
[[unused]] int b() { return 42; }
As a lambda and leave it on a single line, even if that was disallowed
by the format style.
llvm-svn: 329816
Diffstat (limited to 'clang/unittests/Format/FormatTest.cpp')
-rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 43225304670..4abf978b721 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -6078,6 +6078,21 @@ TEST_F(FormatTest, UnderstandsSquareAttributes) { verifyFormat("void f() [[deprecated(\"so sorry\")]];"); verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n" " [[unused]] aaaaaaaaaaaaaaaaaaaaaaa(int i);"); + + // Make sure we do not mistake attributes for array subscripts. + verifyFormat("int a() {}\n" + "[[unused]] int b() {}\n"); + + // On the other hand, we still need to correctly find array subscripts. + verifyFormat("int a = std::vector<int>{1, 2, 3}[0];"); + + // Make sure we do not parse attributes as lambda introducers. + FormatStyle MultiLineFunctions = getLLVMStyle(); + MultiLineFunctions.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None; + verifyFormat("[[unused]] int b() {\n" + " return 42;\n" + "}\n", + MultiLineFunctions); } TEST_F(FormatTest, UnderstandsEllipsis) { |