Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -1344,8 +1344,10 @@ Contexts.back().IsExpression = false; } else if (Current.is(tok::kw_new)) { Contexts.back().CanBeExpression = false; - } else if (Current.isOneOf(tok::semi, tok::exclaim)) { + } else if (Current.isOneOf(tok::semi, tok::exclaim) && + !(Current.Previous && Current.Previous->is(tok::kw_operator))) { // This should be the condition or increment in a for-loop. + // but not operator !() Contexts.back().IsExpression = true; } } @@ -2085,6 +2087,8 @@ return Next; if (Next->is(TT_OverloadedOperator)) continue; + if (Next->isOneOf(tok::star, tok::arrow)) + continue; if (Next->isOneOf(tok::kw_new, tok::kw_delete)) { // For 'new[]' and 'delete[]'. if (Next->Next && Next->Next->is(tok::l_square) && Next->Next->Next && Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -6111,7 +6111,13 @@ "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!() {}\n", Style); verifyFormat("void *operator new(std::size_t s);", // No break here. Style);