[PATCH] D48880: [Sema] Fix crash in getConstructorName.

Ilya Biryukov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 3 06:52:25 PDT 2018


ilya-biryukov created this revision.
ilya-biryukov added reviewers: bkramer, rsmith.

Can happen when getConstructorName is called on invalid decls,
specifically the ones that do not have the injected class name.


Repository:
  rC Clang

https://reviews.llvm.org/D48880

Files:
  lib/Sema/SemaExprCXX.cpp
  test/Sema/injected-class-name-crash.cpp


Index: test/Sema/injected-class-name-crash.cpp
===================================================================
--- /dev/null
+++ test/Sema/injected-class-name-crash.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+template <class T>
+struct X : public Foo<Bar { // expected-error {{unknown template name 'Foo'}} expected-error {{use of undeclared identifier 'Bar'}}
+  X();
+}; // expected-error {{expected '{' after base class list}}
+
+
+template <class T>
+X<T>::X() {
+}
Index: lib/Sema/SemaExprCXX.cpp
===================================================================
--- lib/Sema/SemaExprCXX.cpp
+++ lib/Sema/SemaExprCXX.cpp
@@ -96,7 +96,8 @@
     return ParsedType::make(T);
   }
 
-  if (SS.isNotEmpty() && RequireCompleteDeclContext(SS, CurClass))
+  if ((SS.isNotEmpty() && RequireCompleteDeclContext(SS, CurClass)) ||
+      CurClass->isInvalidDecl())
     return ParsedType();
 
   // Find the injected-class-name declaration. Note that we make no attempt to


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D48880.153909.patch
Type: text/x-patch
Size: 997 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180703/5a16b9a8/attachment.bin>


More information about the cfe-commits mailing list