r175554 - Add missing clang-format null pointer check..

Daniel Jasper djasper at google.com
Tue Feb 19 12:05:42 PST 2013


Author: djasper
Date: Tue Feb 19 14:05:41 2013
New Revision: 175554

URL: http://llvm.org/viewvc/llvm-project?rev=175554&view=rev
Log:
Add missing clang-format null pointer check..

.. and a test that triggers it in valid albeit questionable code.

Modified:
    cfe/trunk/lib/Format/TokenAnnotator.cpp
    cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=175554&r1=175553&r2=175554&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Tue Feb 19 14:05:41 2013
@@ -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) ||

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=175554&r1=175553&r2=175554&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Feb 19 14:05:41 2013
@@ -937,6 +937,8 @@ TEST_F(FormatTest, MacroDefinitionsWithI
                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) {





More information about the cfe-commits mailing list