[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
Wed Feb 10 11:53:35 PST 2016


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

- Added test for PR25181


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
@@ -293,6 +293,8 @@
 }
 
 void Parser::ParseLexedMethodDeclaration(LateParsedMethodDeclaration &LM) {
+  if (!LM.Method)
+    return;
   // If this is a member template, introduce the template parameter scope.
   ParseScope TemplateScope(this, Scope::TemplateParamScope, LM.TemplateScope);
   TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D17072.47501.patch
Type: text/x-patch
Size: 1228 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160210/bcca7312/attachment.bin>


More information about the cfe-commits mailing list