[PATCH] D80008: [clang-format] [PR45942] [[nodiscard]] causes && to be miss interpreted as BinaryOperators
MyDeveloperDay via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri May 15 13:37:30 PDT 2020
MyDeveloperDay updated this revision to Diff 264325.
MyDeveloperDay added a comment.
pre-merge tests showed I wasn't quite rebased however it overlaps with D79354: [clang-format] [PR34574] Handle [[nodiscard]] attribute in class declaration <https://reviews.llvm.org/D79354>
However I feel I made a mistake with the previous fix because the l_square and r_square haven't always been assigned to be of type TT_AttributeSquare yet.
Update this patch so the test from both revision still work.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D80008/new/
https://reviews.llvm.org/D80008
Files:
clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/FormatTest.cpp
Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -8014,6 +8014,30 @@
MultiLineFunctions);
}
+TEST_F(FormatTest, AttributeClass) {
+ FormatStyle Style = getChromiumStyle(FormatStyle::LK_Cpp);
+ verifyFormat("class S {\n"
+ " S(S&&) = default;\n"
+ "};",
+ Style);
+ verifyFormat("class [[nodiscard]] S {\n"
+ " S(S&&) = default;\n"
+ "};",
+ Style);
+ verifyFormat("class __attribute((maybeunused)) S {\n"
+ " S(S&&) = default;\n"
+ "};",
+ Style);
+ verifyFormat("struct S {\n"
+ " S(S&&) = default;\n"
+ "};",
+ Style);
+ verifyFormat("struct [[nodiscard]] S {\n"
+ " S(S&&) = default;\n"
+ "};",
+ Style);
+}
+
TEST_F(FormatTest, AttributePenaltyBreaking) {
FormatStyle Style = getLLVMStyle();
verifyFormat("void ABCDEFGH::ABCDEFGHIJKLMN(\n"
Index: clang/lib/Format/UnwrappedLineParser.cpp
===================================================================
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2404,7 +2404,7 @@
// An [[attribute]] can be before the identifier.
while (FormatTok->isOneOf(tok::identifier, tok::coloncolon, tok::hashhash,
tok::kw___attribute, tok::kw___declspec,
- tok::kw_alignas, TT_AttributeSquare) ||
+ tok::kw_alignas, tok::l_square, tok::r_square) ||
((Style.Language == FormatStyle::LK_Java ||
Style.Language == FormatStyle::LK_JavaScript) &&
FormatTok->isOneOf(tok::period, tok::comma))) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D80008.264325.patch
Type: text/x-patch
Size: 1893 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200515/41f8e2be/attachment-0001.bin>
More information about the cfe-commits
mailing list