[PATCH] D86950: [clang-format] Check that */& after typename macros are pointers/references
Alexander Richardson via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 1 08:16:27 PDT 2020
arichardson created this revision.
arichardson added reviewers: MyDeveloperDay, JakeMerdichAMD, sammccall, curdeius.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
arichardson requested review of this revision.
Depends on D86930 <https://reviews.llvm.org/D86930> (Fix the actual parsing of typename macros)
Depends on D86926 <https://reviews.llvm.org/D86926> (Style argument added to verifyIndependentOfContext())
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D86950
Files:
clang/unittests/Format/FormatTest.cpp
Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -8041,6 +8041,14 @@
verifyFormat("vector<a *__ptr32> v;");
verifyFormat("vector<a *__ptr64> v;");
verifyFormat("vector<a *__capability> v;");
+ FormatStyle TypeMacros = getLLVMStyle();
+ TypeMacros.TypenameMacros = {"LIST"};
+ verifyFormat("vector<LIST(uint64_t)> v;", TypeMacros);
+ verifyFormat("vector<LIST(uint64_t) *> v;", TypeMacros);
+ verifyFormat("vector<LIST(uint64_t) **> v;", TypeMacros);
+ verifyFormat("vector<LIST(uint64_t) *attr> v;", TypeMacros);
+ verifyFormat("vector<A(uint64_t) * attr> v;", TypeMacros); // multiplication
+
FormatStyle CustomQualifier = getLLVMStyle();
// Add indentifers that should not be parsed as a qualifier by default.
CustomQualifier.AttributeMacros.push_back("__my_qualifier");
@@ -8105,6 +8113,9 @@
// a type declaration:
verifyFormat("MACRO(A *__my_qualifier);", CustomQualifier);
verifyFormat("void f() { MACRO(A *__my_qualifier); }", CustomQualifier);
+ // Also check that TypenameMacros prevents parsing it as multiplication:
+ verifyIndependentOfContext("MACRO(LIST(uint64_t) * a);"); // multiplication
+ verifyIndependentOfContext("MACRO(LIST(uint64_t) *a);", TypeMacros); // type
verifyIndependentOfContext("MACRO('0' <= c && c <= '9');");
verifyFormat("void f() { f(float{1}, a * a); }");
@@ -16552,12 +16563,15 @@
verifyFormat("STACK_OF(LIST(int)) a, b;", Macros);
verifyFormat("for (LIST(int) *a = NULL; a;) {\n}", Macros);
verifyFormat("STACK_OF(int) f(LIST(int) *arg);", Macros);
+ verifyFormat("vector<LIST(uint64_t) *attr> x;", Macros);
+ verifyFormat("vector<LIST(uint64_t) *const> f(LIST(uint64_t) *arg);", Macros);
Macros.PointerAlignment = FormatStyle::PAS_Left;
verifyFormat("STACK_OF(int)* a;", Macros);
verifyFormat("STACK_OF(int*)* a;", Macros);
verifyFormat("x = (STACK_OF(uint64_t))*a;", Macros);
verifyFormat("x = (STACK_OF(uint64_t))&a;", Macros);
+ verifyFormat("vector<STACK_OF(uint64_t)* attr> x;", Macros);
}
TEST_F(FormatTest, AmbersandInLamda) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D86950.289182.patch
Type: text/x-patch
Size: 2203 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200901/2052fec5/attachment.bin>
More information about the cfe-commits
mailing list