[PATCH] D79905: [clang-format] [PR44476] Add space between template and attribute
MyDeveloperDay via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed May 13 13:36:35 PDT 2020
MyDeveloperDay created this revision.
MyDeveloperDay added reviewers: krasimir, JakeMerdichAMD, mitchell-stellar, sammccall.
MyDeveloperDay added projects: clang, clang-format.
MyDeveloperDay added a reviewer: abrachet.
https://bugs.llvm.org/show_bug.cgi?id=44476
template <typename T> [[nodiscard]] int a() { return 1; }
get incorrectly formatted to be
template <typename T>[[nodiscard]] int a() { return 1; }
This revision ensure there is a space between them
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D79905
Files:
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp
Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -7667,6 +7667,8 @@
verifyFormat("@[ [NSArray class] ];");
verifyFormat("@[ [foo enum] ];");
+ verifyFormat("template <typename T> [[nodiscard]] int a() { return 1; }");
+
// Make sure we do not parse attributes as lambda introducers.
FormatStyle MultiLineFunctions = getLLVMStyle();
MultiLineFunctions.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None;
Index: clang/lib/Format/TokenAnnotator.cpp
===================================================================
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2896,6 +2896,11 @@
// No whitespace in x(/*foo=*/1), except for JavaScript.
return Style.Language == FormatStyle::LK_JavaScript ||
!Left.TokenText.endswith("=*/");
+
+ // Space between tempalte and attribute
+ // e.g. template <typename T> [[nodiscard]] ...
+ if (Left.is(TT_TemplateCloser) && Right.is(TT_AttributeSquare))
+ return true;
if (Right.is(tok::l_paren)) {
if ((Left.is(tok::r_paren) && Left.is(TT_AttributeParen)) ||
(Left.is(tok::r_square) && Left.is(TT_AttributeSquare)))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D79905.263840.patch
Type: text/x-patch
Size: 1305 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200513/5369ff28/attachment-0001.bin>
More information about the cfe-commits
mailing list