r237688 - clang-format: Improve for-loop formatting.
Daniel Jasper
djasper at google.com
Tue May 19 04:51:39 PDT 2015
Author: djasper
Date: Tue May 19 06:51:39 2015
New Revision: 237688
URL: http://llvm.org/viewvc/llvm-project?rev=237688&view=rev
Log:
clang-format: Improve for-loop formatting.
Before:
for (SmallVectorImpl<TemplateIdAnnotationn *>::iterator I =
Container.begin(),
E = Container.end();
I != E; ++I)
After:
for (SmallVectorImpl<TemplateIdAnnotationn *>::iterator
I = Container.begin(),
E = Container.end();
I != E; ++I)
This fixes llvm.org/PR23544.
Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=237688&r1=237687&r2=237688&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Tue May 19 06:51:39 2015
@@ -568,7 +568,8 @@ private:
case tok::comma:
if (Contexts.back().InCtorInitializer)
Tok->Type = TT_CtorInitializerComma;
- else if (Contexts.back().FirstStartOfName && Contexts.size() == 1) {
+ else if (Contexts.back().FirstStartOfName &&
+ (Contexts.size() == 1 || Line.First->is(tok::kw_for))) {
Contexts.back().FirstStartOfName->PartOfMultiVariableDeclStmt = true;
Line.IsMultiVariableDeclStmt = true;
}
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=237688&r1=237687&r2=237688&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Tue May 19 06:51:39 2015
@@ -557,6 +557,11 @@ TEST_F(FormatTest, FormatsForLoop) {
" I = FD->getDeclsInPrototypeScope().begin(),\n"
" E = FD->getDeclsInPrototypeScope().end();\n"
" I != E; ++I) {\n}");
+ verifyFormat("for (SmallVectorImpl<TemplateIdAnnotationn *>::iterator\n"
+ " I = Container.begin(),\n"
+ " E = Container.end();\n"
+ " I != E; ++I) {\n}",
+ getLLVMStyleWithColumns(76));
verifyFormat(
"for (aaaaaaaaaaaaaaaaa aaaaaaaaaaa = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;\n"
More information about the cfe-commits
mailing list