[PATCH] D114696: [clang-format] regressed default behavior for operator parentheses
MyDeveloperDay via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 29 01:57:41 PST 2021
MyDeveloperDay created this revision.
MyDeveloperDay added reviewers: HazardyKnusperkeks, crayroud, curdeius, owenpan.
MyDeveloperDay added projects: clang, clang-format.
MyDeveloperDay requested review of this revision.
D110833: [clang-format] Refactor SpaceBeforeParens to add options <https://reviews.llvm.org/D110833> regressed behavior of spaces before parentheses for operators, this revision reverts that so that operators are handled as they were before.
I think in hindsight it was a mistake to try and consume operator behaviour in with the function behaviour, I think Operators can be considered a special style. Its seems the code is getting confused as to if this is a function declaration or definition.
I think latterly we can consider adding an operator parentheses specific custom option but this should have been explicitly called out as it can impact projects.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D114696
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
@@ -9164,6 +9164,11 @@
// https://llvm.org/PR50629
// verifyFormat("void f() { operator*(a & a); }");
// verifyFormat("void f() { operator&(a, b * b); }");
+
+ verifyFormat("::operator delete(foo);");
+ verifyFormat("::operator new(n * sizeof(foo));");
+ verifyFormat("foo() { ::operator delete(foo); }");
+ verifyFormat("foo() { ::operator new(n * sizeof(foo)); }");
}
TEST_F(FormatTest, UnderstandsFunctionRefQualification) {
@@ -14096,8 +14101,9 @@
verifyFormat("static_assert (sizeof (char) == 1, \"Impossible!\");", Space);
verifyFormat("int f () throw (Deprecated);", Space);
verifyFormat("typedef void (*cb) (int);", Space);
- verifyFormat("T A::operator() ();", Space);
- verifyFormat("X A::operator++ (T);", Space);
+ // FIXME these tests regressed behaviour.
+ // verifyFormat("T A::operator() ();", Space);
+ // verifyFormat("X A::operator++ (T);", Space);
verifyFormat("auto lambda = [] () { return 0; };", Space);
verifyFormat("int x = int (y);", Space);
@@ -14153,7 +14159,8 @@
verifyFormat("int f() throw (Deprecated);", SomeSpace);
verifyFormat("typedef void (*cb) (int);", SomeSpace);
verifyFormat("T A::operator()();", SomeSpace);
- verifyFormat("X A::operator++ (T);", SomeSpace);
+ // FIXME these tests regressed behaviour.
+ // verifyFormat("X A::operator++ (T);", SomeSpace);
verifyFormat("int x = int (y);", SomeSpace);
verifyFormat("auto lambda = []() { return 0; };", SomeSpace);
@@ -14209,8 +14216,9 @@
SpaceFuncDecl);
verifyFormat("int f () throw(Deprecated);", SpaceFuncDecl);
verifyFormat("typedef void (*cb)(int);", SpaceFuncDecl);
- verifyFormat("T A::operator() ();", SpaceFuncDecl);
- verifyFormat("X A::operator++ (T);", SpaceFuncDecl);
+ // FIXME these tests regressed behaviour.
+ // verifyFormat("T A::operator() ();", SpaceFuncDecl);
+ // verifyFormat("X A::operator++ (T);", SpaceFuncDecl);
verifyFormat("T A::operator()() {}", SpaceFuncDecl);
verifyFormat("auto lambda = []() { return 0; };", SpaceFuncDecl);
verifyFormat("int x = int(y);", SpaceFuncDecl);
@@ -14245,7 +14253,7 @@
verifyFormat("typedef void (*cb)(int);", SpaceFuncDef);
verifyFormat("T A::operator()();", SpaceFuncDef);
verifyFormat("X A::operator++(T);", SpaceFuncDef);
- verifyFormat("T A::operator() () {}", SpaceFuncDef);
+ // verifyFormat("T A::operator() () {}", SpaceFuncDef);
verifyFormat("auto lambda = [] () { return 0; };", SpaceFuncDef);
verifyFormat("int x = int(y);", SpaceFuncDef);
verifyFormat("M(std::size_t R, std::size_t C) : C(C), data(R) {}",
@@ -14320,7 +14328,7 @@
verifyFormat("int f() throw (Deprecated);", SomeSpace2);
verifyFormat("typedef void (*cb) (int);", SomeSpace2);
verifyFormat("T A::operator()();", SomeSpace2);
- verifyFormat("X A::operator++ (T);", SomeSpace2);
+ // verifyFormat("X A::operator++ (T);", SomeSpace2);
verifyFormat("int x = int (y);", SomeSpace2);
verifyFormat("auto lambda = []() { return 0; };", SomeSpace2);
}
Index: clang/lib/Format/TokenAnnotator.cpp
===================================================================
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3169,9 +3169,13 @@
if (Left.isIf(Line.Type != LT_PreprocessorDirective))
return Style.SpaceBeforeParensOptions.AfterControlStatements ||
spaceRequiredBeforeParens(Right);
+
+ // TODO add Operator overloading specific Options to
+ // SpaceBeforeParensOptions
+ if (Right.is(TT_OverloadedOperatorLParen))
+ return spaceRequiredBeforeParens(Right);
// Function declaration or definition
- if (Line.MightBeFunctionDecl && (Left.is(TT_FunctionDeclarationName) ||
- Right.is(TT_OverloadedOperatorLParen))) {
+ if (Line.MightBeFunctionDecl && (Left.is(TT_FunctionDeclarationName))) {
if (Line.mightBeFunctionDefinition())
return Style.SpaceBeforeParensOptions.AfterFunctionDefinitionName ||
spaceRequiredBeforeParens(Right);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D114696.390289.patch
Type: text/x-patch
Size: 4235 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211129/d470457b/attachment-0001.bin>
More information about the cfe-commits
mailing list