HomePhabricator

[clang-format] [PR36294] AlwaysBreakAfterReturnType works incorrectly for some…

Authored by MyDeveloperDay on Nov 12 2019, 1:14 AM.

Description

[clang-format] [PR36294] AlwaysBreakAfterReturnType works incorrectly for some operator functions

Summary:
https://bugs.llvm.org/show_bug.cgi?id=36294

Addressing bug related to returning after return type not being honoured for some operator types.

$ bin/clang-format --style="{BasedOnStyle: llvm, AlwaysBreakAfterReturnType: TopLevelDefinitions}" /tmp/foo.cpp
class Foo {
public:
  bool operator!() const;
  bool operator<(Foo const &) const;
  bool operator*() const;
  bool operator->() const;
  bool operator+() const;
  bool operator-() const;
  bool f() const;
};

bool Foo::operator!() const { return true; }
bool
Foo::operator<(Foo const &) const {
  return true;
}
bool Foo::operator*() const { return true; }
bool Foo::operator->() const { return true; }
bool
Foo::operator+() const {
  return true;
}
bool
Foo::operator-() const {
  return true;
}
bool
Foo::f() const {
  return true;
}

Reviewers: mitchell-stellar, klimek, owenpan, sammccall, rianquinn

Reviewed By: sammccall

Subscribers: merge_guards_bot, cfe-commits

Tags: #clang-format, #clang-tools-extra, #clang

Differential Revision: https://reviews.llvm.org/D69573

Event Timeline

Typz added a subscriber: Typz.Nov 14 2019, 2:39 AM
Typz added inline comments.
/clang/unittests/Format/FormatTest.cpp
14844

There is no test for Middle operator alignment, and it seems to break this case:

Style.PointerAlignment = FormatStyle::PAS_Middle;
verifyFormat("Foo::operator void *();", Style);

(the space between void and * is broken)

I will try to work on a fix.

MyDeveloperDay marked an inline comment as done.Nov 14 2019, 3:59 AM
MyDeveloperDay added inline comments.
/clang/unittests/Format/FormatTest.cpp
14844

ok thanks

Typz added inline comments.Nov 15 2019, 5:06 AM
/clang/unittests/Format/FormatTest.cpp
14844

Could you please have a look to this regression:
https://bugs.llvm.org/show_bug.cgi?id=45357

thanks