Teach clang-format to understand static_asserts better.
authorDaniel Jasper <djasper@google.com>
Thu, 1 Aug 2013 17:58:23 +0000 (17:58 +0000)
committerDaniel Jasper <djasper@google.com>
Thu, 1 Aug 2013 17:58:23 +0000 (17:58 +0000)
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).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@187589 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/Format.cpp
lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTest.cpp

index 290f0597f578917a2778586d65d20f1f7f9e5e1f..f59fb37996eaf7533730dae014c16b47a8ddcd0f 100644 (file)
@@ -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);
   }
index e0e24e27488e78dac950e68c1324ac30e8d2a879..39ebe95a43bc3c90ede64ca7c2b3670fd507c470 100644 (file)
@@ -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;
index 6a5f0228fc4aba39329d7d967e4afc28916912f3..e2bb65d675bac7c2a2515b39575ef50bc437bffe 100644 (file)
@@ -3687,6 +3687,11 @@ TEST_F(FormatTest, UnderstandsRvalueReferences) {
   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) {