Index: WhitespaceManager.cpp =================================================================== --- WhitespaceManager.cpp +++ WhitespaceManager.cpp @@ -1,9 +1,10 @@ //===--- WhitespaceManager.cpp - Format C++ code --------------------------===// // -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// The LLVM Compiler Infrastructure // +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// //===----------------------------------------------------------------------===// /// /// \file @@ -679,13 +680,17 @@ case FormatStyle::UT_Always: { unsigned FirstTabWidth = Style.TabWidth - WhitespaceStartColumn % Style.TabWidth; - // Indent with tabs only when there's at least one full tab. - if (FirstTabWidth + Style.TabWidth <= Spaces) { + // Insert only spaces when we want to end up before the next tab. + if (Spaces < FirstTabWidth) { + Text.append(Spaces, ' '); + } else { + // Align to next tab. Spaces -= FirstTabWidth; Text.append("\t"); + + Text.append(Spaces / Style.TabWidth, '\t'); + Text.append(Spaces % Style.TabWidth, ' '); } - Text.append(Spaces / Style.TabWidth, '\t'); - Text.append(Spaces % Style.TabWidth, ' '); break; } case FormatStyle::UT_ForIndentation: