diff options
author | mydeveloperday <mydeveloperday@gmail.com> | 2019-11-12 09:14:51 +0000 |
---|---|---|
committer | paulhoad <mydeveloperday@gmail.com> | 2019-11-12 09:25:00 +0000 |
commit | a75f8d98d7ac9e557b238a229a9a2647c71feed1 (patch) | |
tree | 677318b1b264b0fb180eb060328be49e0f760197 /clang/unittests/Format/FormatTest.cpp | |
parent | 874b6495b5fd6d7e2dc91d6a756eea67486ea7bb (diff) | |
download | bcm5719-llvm-a75f8d98d7ac9e557b238a229a9a2647c71feed1.tar.gz bcm5719-llvm-a75f8d98d7ac9e557b238a229a9a2647c71feed1.zip |
[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
Diffstat (limited to 'clang/unittests/Format/FormatTest.cpp')
-rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 90 |
1 files changed, 89 insertions, 1 deletions
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index eacb389400b..cef2b0b2755 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -6134,7 +6134,48 @@ TEST_F(FormatTest, ReturnTypeBreakingStyle) { "void\n" "A::operator>>() {}\n" "void\n" - "A::operator+() {}\n", + "A::operator+() {}\n" + "void\n" + "A::operator*() {}\n" + "void\n" + "A::operator->() {}\n" + "void\n" + "A::operator void *() {}\n" + "void\n" + "A::operator void &() {}\n" + "void\n" + "A::operator void &&() {}\n" + "void\n" + "A::operator char *() {}\n" + "void\n" + "A::operator[]() {}\n" + "void\n" + "A::operator!() {}\n", + Style); + verifyFormat("constexpr auto\n" + "operator()() const -> reference {}\n" + "constexpr auto\n" + "operator>>() const -> reference {}\n" + "constexpr auto\n" + "operator+() const -> reference {}\n" + "constexpr auto\n" + "operator*() const -> reference {}\n" + "constexpr auto\n" + "operator->() const -> reference {}\n" + "constexpr auto\n" + "operator++() const -> reference {}\n" + "constexpr auto\n" + "operator void *() const -> reference {}\n" + "constexpr auto\n" + "operator void &() const -> reference {}\n" + "constexpr auto\n" + "operator void &&() const -> reference {}\n" + "constexpr auto\n" + "operator char *() const -> reference {}\n" + "constexpr auto\n" + "operator!() const -> reference {}\n" + "constexpr auto\n" + "operator[]() const -> reference {}\n", Style); verifyFormat("void *operator new(std::size_t s);", // No break here. Style); @@ -14755,6 +14796,53 @@ TEST_F(FormatTest, STLWhileNotDefineChed) { "#endif // while"); } +TEST_F(FormatTest, OperatorSpacing) { + FormatStyle Style = getLLVMStyle(); + Style.PointerAlignment = FormatStyle::PAS_Right; + verifyFormat("Foo::operator*();", Style); + verifyFormat("Foo::operator void *();", Style); + verifyFormat("Foo::operator()(void *);", Style); + verifyFormat("Foo::operator*(void *);", Style); + verifyFormat("Foo::operator*();", Style); + verifyFormat("operator*(int (*)(), class Foo);", Style); + + verifyFormat("Foo::operator&();", Style); + verifyFormat("Foo::operator void &();", Style); + verifyFormat("Foo::operator()(void &);", Style); + verifyFormat("Foo::operator&(void &);", Style); + verifyFormat("Foo::operator&();", Style); + verifyFormat("operator&(int (&)(), class Foo);", Style); + + verifyFormat("Foo::operator&&();", Style); + verifyFormat("Foo::operator void &&();", Style); + verifyFormat("Foo::operator()(void &&);", Style); + verifyFormat("Foo::operator&&(void &&);", Style); + verifyFormat("Foo::operator&&();", Style); + verifyFormat("operator&&(int(&&)(), class Foo);", Style); + + Style.PointerAlignment = FormatStyle::PAS_Left; + verifyFormat("Foo::operator*();", Style); + verifyFormat("Foo::operator void*();", Style); + verifyFormat("Foo::operator()(void*);", Style); + verifyFormat("Foo::operator*(void*);", Style); + verifyFormat("Foo::operator*();", Style); + verifyFormat("operator*(int (*)(), class Foo);", Style); + + verifyFormat("Foo::operator&();", Style); + verifyFormat("Foo::operator void&();", Style); + verifyFormat("Foo::operator()(void&);", Style); + verifyFormat("Foo::operator&(void&);", Style); + verifyFormat("Foo::operator&();", Style); + verifyFormat("operator&(int (&)(), class Foo);", Style); + + verifyFormat("Foo::operator&&();", Style); + verifyFormat("Foo::operator void&&();", Style); + verifyFormat("Foo::operator()(void&&);", Style); + verifyFormat("Foo::operator&&(void&&);", Style); + verifyFormat("Foo::operator&&();", Style); + verifyFormat("operator&&(int(&&)(), class Foo);", Style); +} + } // namespace } // namespace format } // namespace clang |