[PATCH] clang-format: Fix space in for-each macro definition
strager
strager.nds at gmail.com
Thu Jun 4 18:49:34 PDT 2015
Hi djasper,
The C preprocessor definition of a for-each macro was being
improperly formatted. A space was being inserted between the
macro name and the opening parenthesis. Fix the extra space
by excluding such cases from the ForEachMacros checks.
http://reviews.llvm.org/D10266
Files:
lib/Format/Format.cpp
test/Format/for-each-macros.cpp
Index: lib/Format/Format.cpp
===================================================================
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -1122,9 +1122,12 @@
Column = FormatTok->LastLineColumnWidth;
}
- if (std::find(ForEachMacros.begin(), ForEachMacros.end(),
- FormatTok->Tok.getIdentifierInfo()) != ForEachMacros.end())
- FormatTok->Type = TT_ForEachMacro;
+ if (!(Tokens.size() > 0 && Tokens.back()->Tok.getIdentifierInfo() &&
+ Tokens.back()->Tok.getIdentifierInfo()->getPPKeywordID() ==
+ tok::pp_define))
+ if (std::find(ForEachMacros.begin(), ForEachMacros.end(),
+ FormatTok->Tok.getIdentifierInfo()) != ForEachMacros.end())
+ FormatTok->Type = TT_ForEachMacro;
return FormatTok;
}
Index: test/Format/for-each-macros.cpp
===================================================================
--- /dev/null
+++ test/Format/for-each-macros.cpp
@@ -0,0 +1,13 @@
+// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp
+// RUN: clang-format -style=LLVM -i %t.cpp
+// RUN: FileCheck -strict-whitespace -input-file=%t.cpp %s
+
+// CHECK: {{foreach\(x\)}}
+#define foreach(x)
+
+#undef foreach
+// CHECK: {{foreach \(x\)}}
+#define foreach (x)
+
+// CHECK: {{foreach \(x\)}}
+foreach(x) {}
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D10266.27169.patch
Type: text/x-patch
Size: 1295 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150605/c0edd825/attachment.bin>
More information about the cfe-commits
mailing list