summaryrefslogtreecommitdiffstats
path: root/clang/unittests/Format/FormatTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/unittests/Format/FormatTest.cpp')
-rw-r--r--clang/unittests/Format/FormatTest.cpp15
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) {
OpenPOWER on IntegriCloud