From: Daniel Jasper Date: Thu, 1 Aug 2013 17:58:23 +0000 (+0000) Subject: Teach clang-format to understand static_asserts better. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b7000ca629da16164f0073f5a7f9459ddf5ba281;p=clang Teach clang-format to understand static_asserts better. Before: template class A { static_assert(B &&C, "Something is wrong"); }; After: template class A { static_assert(B && C, "Something is wrong"); }; (Note the spacing around '&&'). Also change the identifier table to always understand all C++11 keywords (which seems like the right thing to do). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@187589 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index 290f0597f5..f59fb37996 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -1330,7 +1330,7 @@ public: FormatTokenLexer(Lexer &Lex, SourceManager &SourceMgr, encoding::Encoding Encoding) : FormatTok(NULL), GreaterStashed(false), TrailingWhitespace(0), Lex(Lex), - SourceMgr(SourceMgr), IdentTable(Lex.getLangOpts()), + SourceMgr(SourceMgr), IdentTable(getFormattingLangOpts()), Encoding(Encoding) { Lex.SetKeepWhitespaceMode(true); } diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index e0e24e2748..39ebe95a43 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -93,6 +93,9 @@ private: } } + if (Left->Previous && Left->Previous->is(tok::kw_static_assert)) + Contexts.back().IsExpression = true; + if (StartsObjCMethodExpr) { Contexts.back().ColonIsObjCMethodExpr = true; Left->Type = TT_ObjCMethodExpr; diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 6a5f0228fc..e2bb65d675 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -3687,6 +3687,11 @@ TEST_F(FormatTest, UnderstandsRvalueReferences) { verifyIndependentOfContext("A a;"); verifyGoogleFormat("A a;"); verifyGoogleFormat("A a;"); + + // Not rvalue references: + verifyFormat("template class A {\n" + " static_assert(B && C, \"Something is wrong\");\n" + "};"); } TEST_F(FormatTest, FormatsBinaryOperatorsPrecedingEquals) {