[PATCH] D17072: Return immediatedly if Method is null, otherwise you'll get a crash when dyn_cast is called with a nullptr

don hinton via cfe-commits cfe-commits at lists.llvm.org
Sat Feb 13 19:09:49 PST 2016


hintonda updated this revision to Diff 47923.
hintonda added a comment.

- Only call HandleMemberFunctionDeclDelays() for valid NamedDecl pointers.

  HandleMemberFunctionDeclDelays() adds LateParsedMethodDeclaration elements to LateParsedDeclarations if the method has default args or exception-specifications.  If null Methods are added, they will assert when cast in ParseLexedMethodDeclaration().


http://reviews.llvm.org/D17072

Files:
  lib/Parse/ParseCXXInlineMethods.cpp
  test/SemaCXX/pr25181-crash-on-invalid.cpp

Index: test/SemaCXX/pr25181-crash-on-invalid.cpp
===================================================================
--- /dev/null
+++ test/SemaCXX/pr25181-crash-on-invalid.cpp
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+// Don't crash (PR25181).
+
+template <typename T> class Foo { // expected-note {{template parameter is declared here}}
+  template <typename T> // expected-error {{declaration of 'T' shadows template parameter}}
+  void Foo<T>::method(T *) const throw() {} // expected-error {{nested name specifier 'Foo<T>::' for declaration does not refer into a class, class template or class template partial specialization}}
+};
Index: lib/Parse/ParseCXXInlineMethods.cpp
===================================================================
--- lib/Parse/ParseCXXInlineMethods.cpp
+++ lib/Parse/ParseCXXInlineMethods.cpp
@@ -52,7 +52,8 @@
     }
   }
 
-  HandleMemberFunctionDeclDelays(D, FnD);
+  if (FnD)
+    HandleMemberFunctionDeclDelays(D, FnD);
 
   D.complete(FnD);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D17072.47923.patch
Type: text/x-patch
Size: 1015 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160214/438aec21/attachment.bin>


More information about the cfe-commits mailing list