Add missing clang-format null pointer check..
authorDaniel Jasper <djasper@google.com>
Tue, 19 Feb 2013 20:05:41 +0000 (20:05 +0000)
committerDaniel Jasper <djasper@google.com>
Tue, 19 Feb 2013 20:05:41 +0000 (20:05 +0000)
.. and a test that triggers it in valid albeit questionable code.

llvm-svn: 175554

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

index d9368c3..ac7301e 100644 (file)
@@ -592,7 +592,8 @@ private:
         else
           Current.Type = TT_BlockComment;
       } else if (Current.is(tok::r_paren)) {
-        bool ParensNotExpr = Current.Parent->Type == TT_PointerOrReference ||
+        bool ParensNotExpr = !Current.Parent ||
+                             Current.Parent->Type == TT_PointerOrReference ||
                              Current.Parent->Type == TT_TemplateCloser;
         bool ParensCouldEndDecl =
             !Current.Children.empty() && (Current.Children[0].is(tok::equal) ||
index 3a1e9dc..05e5d37 100644 (file)
@@ -937,6 +937,8 @@ TEST_F(FormatTest, MacroDefinitionsWithIncompleteCode) {
                getLLVMStyleWithColumns(20));
 
   verifyFormat("#define A template <typename T>");
+  verifyFormat("#define STR(x) #x\n"
+               "f(STR(this_is_a_string_literal{));");
 }
 
 TEST_F(FormatTest, IndentPreprocessorDirectivesAtZero) {