MyDeveloperDay created this revision.
MyDeveloperDay added reviewers: rolandschulz, reuk, djasper, klimek.
MyDeveloperDay added a project: clang-tools-extra.
Addresses http://llvm.org/PR40418
When using `AlignConsecutiveDeclarations: true`
variables with Attributes would not be aligned correctly
void f(int extremlylongparametername1,
long extremlylongparametername2,
int[[clang::nodiscard]] extremlylongparametername3,
int __attribute__((clang::nodiscard))
extremlylongparametername4) {
int a;
unsigned long b;
int[[clang::nodiscard]] c;
int __attribute__((clang::nodiscard)) d;
}
following this change, both parameters and variables with attributes will be
aligned (space permitting)
void f(int extremlylongparametername1,
long extremlylongparametername2,
int [[clang::nodiscard]]
extremlylongparametername3,
int __attribute__((clang::nodiscard))
extremlylongparametername4) {
int a;
unsigned longb;
int [[clang::nodiscard]] c;
int __attribute__((clang::nodiscard)) d;
}
https://reviews.llvm.org/D59332
Files:
clang/lib/Format/WhitespaceManager.cpp
clang/unittests/Format/FormatTest.cpp
Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -10135,6 +10135,47 @@
" unsigned c;\n"
"}",
Alignment);
+
+ // See llvm.org/PR40418
+ verifyFormat(
+ "void f(int extremlylongparametername1,\n"
+ " long extremlylongparametername2,\n"
+ " int [[a::b]] extremlylongparametername3,\n"
+ " int __attribute__((a::b)) extremlylongparametername4) "
+ "{}\n",
+ Alignment);
+
+ verifyFormat("void f(int extremlylongparametername1,\n"
+ " long extremlylongparametername2,\n"
+ " int [[deprecated]] "
+ "extremlylongparametername3,\n"
+ " int __attribute__((deprecated)) "
+ "extremlylongparametername4) "
+ "{}\n",
+ Alignment);
+
+ verifyFormat("int a;\n"
+ "unsigned longb;\n"
+ "int __attribute__((a::b)) d;\n"
+ "int [[a::b]] c;\n"
+ "int __attribute__((a::b)) e;\n"
+ "int __attribute__((depreciated)) f;\n"
+ "int __attribute__((aligned(16))) g;\n",
+ Alignment);
+
+ verifyFormat("int a;\n"
+ "unsigned longb;\n"
+ "int __attribute__((a::b)) d;\n"
+ "int [[deprecated]] c;\n"
+ "int __attribute__((a::b)) e;\n",
+ Alignment);
+
+ verifyFormat("int a;\n"
+ "unsigned longb;\n"
+ "int __attribute__((deprecated)) de;\n"
+ "int [[deprecated]] c;\n"
+ "int __attribute__((a::b)) e;\n",
+ Alignment);
}
TEST_F(FormatTest, LinuxBraceBreaking) {
Index: clang/lib/Format/WhitespaceManager.cpp
===
--- clang/lib/Format/WhitespaceManager.cpp
+++ clang/lib/Format/WhitespaceManager.cpp
@@ -17,8 +17,8 @@
namespace clang {
namespace format {
-bool WhitespaceManager::Change::IsBeforeInFile::
-operator()(const Change , const Change ) const {
+bool WhitespaceManager::Change::IsBeforeInFile::operator()(
+const Change , const Change ) const {
return SourceMgr.isBeforeInTranslationUnit(
C1.OriginalWhitespaceRange.getBegin(),
C2.OriginalWhitespaceRange.getBegin());
@@ -465,6 +465,19 @@
// definitions.
return C.Tok->is(TT_StartOfName) ||
C.Tok->is(TT_FunctionDeclarationName) ||
+ C.Tok->startsSequence(
+ tok::l_paren, tok::l_paren, tok::identifier,
tok::coloncolon,
+ tok::identifier, tok::r_paren, tok::r_paren) ||
+ C.Tok->startsSequence(tok::l_square, tok::l_square,
+ tok::identifier, tok::coloncolon,
+ tok::identifier, tok::r_square,
+ tok::r_square) ||
+ C.Tok->startsSequence(tok::l_square, tok::l_square,
+ tok::identifier, tok::r_square,
+ tok::r_square) ||
+ C.Tok->startsSequence(tok::l_paren, tok::l_paren,
+ tok::identifier, tok::r_paren,
+