summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/TokenAnnotator.cpp
diff options
context:
space:
mode:
authorKrasimir Georgiev <krasimir@google.com>2020-01-17 13:26:24 +0100
committerHans Wennborg <hans@chromium.org>2020-03-02 11:19:33 +0100
commit99e5b2ff9df5ca4c7fe13b63f60d953058cd9ca3 (patch)
tree22ef6f07925ad4cc88170da012679042ac21fe0e /clang/lib/Format/TokenAnnotator.cpp
parent6b16ce944fef5f3b30b7dcc001b3af478e038668 (diff)
downloadbcm5719-llvm-99e5b2ff9df5ca4c7fe13b63f60d953058cd9ca3.tar.gz
bcm5719-llvm-99e5b2ff9df5ca4c7fe13b63f60d953058cd9ca3.zip
clang-format: fix spacing in `operator const char*()`
Summary: Revision a75f8d98d7ac9e557b238a229a9a2647c71feed1 fixed spacing for operators, but caused the const and non-const versions to diverge: ``` // With Style.PointerAlignment = FormatStyle::PAS_Left: struct A { operator char*() { return ""; } operator const char *() const { return ""; } }; ``` The code was checking if the type specifier was directly preceded by `operator`. However there could be comments and `const/volatile` in between. Reviewers: mprobst Reviewed By: mprobst Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D72911 (cherry picked from commit 33463cfba2be7c8d6c08e666123cc34f114a1f3e)
Diffstat (limited to 'clang/lib/Format/TokenAnnotator.cpp')
-rw-r--r--clang/lib/Format/TokenAnnotator.cpp15
1 files changed, 11 insertions, 4 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 88564e02f23..70bcd7048c5 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2707,10 +2707,17 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
return false;
if (Right.isOneOf(tok::star, tok::amp, tok::ampamp) &&
(Left.is(tok::identifier) || Left.isSimpleTypeSpecifier()) &&
- Left.Previous && Left.Previous->is(tok::kw_operator))
- // Space between the type and the *
- // operator void*(), operator char*(), operator Foo*() dependant
- // on PointerAlignment style.
+ // Space between the type and the * in:
+ // operator void*()
+ // operator char*()
+ // operator /*comment*/ const char*()
+ // operator volatile /*comment*/ char*()
+ // operator Foo*()
+ // dependent on PointerAlignment style.
+ Left.Previous &&
+ (Left.Previous->endsSequence(tok::kw_operator) ||
+ Left.Previous->endsSequence(tok::kw_const, tok::kw_operator) ||
+ Left.Previous->endsSequence(tok::kw_volatile, tok::kw_operator)))
return (Style.PointerAlignment != FormatStyle::PAS_Left);
const auto SpaceRequiredForArrayInitializerLSquare =
[](const FormatToken &LSquareTok, const FormatStyle &Style) {
OpenPOWER on IntegriCloud