From: Andi-Bogdan Postelnicu Date: Tue, 7 Mar 2017 14:48:02 +0000 (+0000) Subject: [clang-format] Fixed indent issue when adding a comment at the end of a return type... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5f5f0e7c70fecb9188cc8e5d3e3eeb2848f44cd2;p=clang [clang-format] Fixed indent issue when adding a comment at the end of a return type in named function declaration. Differential Revision: https://reviews.llvm.org/D30646 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@297143 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 42c92c4eca..1a3b352049 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -1166,9 +1166,9 @@ private: return false; // Skip "const" as it does not have an influence on whether this is a name. - FormatToken *PreviousNotConst = Tok.Previous; + FormatToken *PreviousNotConst = Tok.getPreviousNonComment(); while (PreviousNotConst && PreviousNotConst->is(tok::kw_const)) - PreviousNotConst = PreviousNotConst->Previous; + PreviousNotConst = PreviousNotConst->getPreviousNonComment(); if (!PreviousNotConst) return false; diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 7ab0c752d1..54c5f27978 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -5325,6 +5325,11 @@ TEST_F(FormatTest, BreaksLongDeclarations) { " vector>\n" " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);"); + + verifyFormat("template // Templates on own line.\n" + "static int // Some comment.\n" + "MyFunction(int a);", + getLLVMStyle()); } TEST_F(FormatTest, FormatsArrays) {