Author: djasper Date: Thu Aug 1 12:58:23 2013 New Revision: 187589 URL: http://llvm.org/viewvc/llvm-project?rev=187589&view=rev Log: Teach clang-format to understand static_asserts better.
Before: template <bool B, bool C> class A { static_assert(B &&C, "Something is wrong"); }; After: template <bool B, bool C> 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). Modified: cfe/trunk/lib/Format/Format.cpp cfe/trunk/lib/Format/TokenAnnotator.cpp cfe/trunk/unittests/Format/FormatTest.cpp Modified: cfe/trunk/lib/Format/Format.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=187589&r1=187588&r2=187589&view=diff ============================================================================== --- cfe/trunk/lib/Format/Format.cpp (original) +++ cfe/trunk/lib/Format/Format.cpp Thu Aug 1 12:58:23 2013 @@ -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); } Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=187589&r1=187588&r2=187589&view=diff ============================================================================== --- cfe/trunk/lib/Format/TokenAnnotator.cpp (original) +++ cfe/trunk/lib/Format/TokenAnnotator.cpp Thu Aug 1 12:58:23 2013 @@ -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; Modified: cfe/trunk/unittests/Format/FormatTest.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=187589&r1=187588&r2=187589&view=diff ============================================================================== --- cfe/trunk/unittests/Format/FormatTest.cpp (original) +++ cfe/trunk/unittests/Format/FormatTest.cpp Thu Aug 1 12:58:23 2013 @@ -3687,6 +3687,11 @@ TEST_F(FormatTest, UnderstandsRvalueRefe verifyIndependentOfContext("A<int &&, int &&> a;"); verifyGoogleFormat("A<int&&> a;"); verifyGoogleFormat("A<int&&, int&&> a;"); + + // Not rvalue references: + verifyFormat("template <bool B, bool C> class A {\n" + " static_assert(B && C, \"Something is wrong\");\n" + "};"); } TEST_F(FormatTest, FormatsBinaryOperatorsPrecedingEquals) { _______________________________________________ cfe-commits mailing list cfe-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits