[PATCH] clang-format: Treat 'operator new' as function name.
strager
strager.nds at gmail.com
Tue Jun 30 22:36:42 PDT 2015
Hi djasper, klimek,
'operator new' was not being treated as a function name in
one case, so AlwaysBreakAfterDeclarationReturnType and
AlwaysBreakAfterDefinitionReturnType never triggered. This
bug affected other operators as well.
Depends on D10370.
http://reviews.llvm.org/D10860
Files:
lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTest.cpp
Index: lib/Format/TokenAnnotator.cpp
===================================================================
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -1540,7 +1540,7 @@
Current->MustBreakBefore || mustBreakBefore(Line, *Current);
if (!Current->MustBreakBefore && InFunctionDecl &&
- Current->is(TT_FunctionDeclarationName)) {
+ Current->isOneOf(tok::kw_operator, TT_FunctionDeclarationName)) {
// FIXME: Line.Last points to other characters than tok::semi
// and tok::lbrace.
bool IsDefinition = !Line.Last->isOneOf(tok::semi, tok::comment);
Index: unittests/Format/FormatTest.cpp
===================================================================
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -4668,6 +4668,11 @@
"T *\n"
"f(T &c);\n",
Style);
+ verifyFormat("void *\n"
+ "operator new(std::size_t);",
+ Style);
+ verifyFormat("void *operator new(std::size_t) {}",
+ Style);
Style.BreakBeforeBraces = FormatStyle::BS_Stroustrup;
verifyFormat("const char *f(void) { return \"\"; }\n"
"const char *\n"
@@ -4716,6 +4721,11 @@
"}\n"
"template <class T> T *f(T &c);\n", // No break here.
Style);
+ verifyFormat("void *operator new(std::size_t);", // No break here.
+ Style);
+ verifyFormat("void *\n"
+ "operator new(std::size_t) {}",
+ Style);
Style.BreakBeforeBraces = FormatStyle::BS_Stroustrup;
verifyFormat("const char *\n"
"f(void)\n" // Break here.
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D10860.28845.patch
Type: text/x-patch
Size: 1686 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150701/7ab93a61/attachment.bin>
More information about the cfe-commits
mailing list