[PATCH] D57655: clang-format with UseTab: Always sometimes doesn't insert the right amount of tabs.
Alexander Kornienko via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 15 15:07:20 PST 2019
This revision was automatically updated to reflect the committed changes.
Closed by commit rC354183: clang-format with UseTab: Always sometimes doesn't insert the right amount of… (authored by alexfh, committed by ).
Changed prior to commit:
https://reviews.llvm.org/D57655?vs=186629&id=187096#toc
Repository:
rC Clang
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D57655/new/
https://reviews.llvm.org/D57655
Files:
lib/Format/WhitespaceManager.cpp
unittests/Format/FormatTest.cpp
Index: lib/Format/WhitespaceManager.cpp
===================================================================
--- lib/Format/WhitespaceManager.cpp
+++ lib/Format/WhitespaceManager.cpp
@@ -679,11 +679,15 @@
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) {
- Spaces -= FirstTabWidth;
- Text.append("\t");
+ // Insert only spaces when we want to end up before the next tab.
+ if (Spaces < FirstTabWidth || Spaces == 1) {
+ Text.append(Spaces, ' ');
+ break;
}
+ // Align to the next tab.
+ Spaces -= FirstTabWidth;
+ Text.append("\t");
+
Text.append(Spaces / Style.TabWidth, '\t');
Text.append(Spaces % Style.TabWidth, ' ');
break;
Index: unittests/Format/FormatTest.cpp
===================================================================
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -8751,6 +8751,9 @@
"\t\t parameter2); \\\n"
"\t}",
Tab);
+ verifyFormat("int a;\t // x\n"
+ "int bbbbbbbb; // x\n",
+ Tab);
Tab.TabWidth = 4;
Tab.IndentWidth = 8;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57655.187096.patch
Type: text/x-patch
Size: 1320 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190215/ee2d47b3/attachment.bin>
More information about the cfe-commits
mailing list