summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIlya Biryukov <ibiryukov@google.com>2018-07-04 08:50:12 +0000
committerIlya Biryukov <ibiryukov@google.com>2018-07-04 08:50:12 +0000
commitc8c9b4da91fdf2e1bd938704f419763a969b56ed (patch)
tree3ab271057c89c576f7602693c095b6c88c63c377
parent4f874f4052f3375bfbd0d3a7655ee049d3cccdd8 (diff)
[Sema] Fix crash in getConstructorName.
Summary: Can happen when getConstructorName is called on invalid decls, specifically the ones that do not have the injected class name. Reviewers: bkramer, rsmith Reviewed By: rsmith Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D48880 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@336244 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Sema/SemaExprCXX.cpp2
-rw-r--r--test/SemaCXX/injected-class-name-crash.cpp11
2 files changed, 13 insertions, 0 deletions
diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp
index db47931348..8dd9c19bd3 100644
--- a/lib/Sema/SemaExprCXX.cpp
+++ b/lib/Sema/SemaExprCXX.cpp
@@ -113,6 +113,8 @@ ParsedType Sema::getConstructorName(IdentifierInfo &II,
break;
}
}
+ if (!InjectedClassName && CurClass->isInvalidDecl())
+ return ParsedType();
assert(InjectedClassName && "couldn't find injected class name");
QualType T = Context.getTypeDeclType(InjectedClassName);
diff --git a/test/SemaCXX/injected-class-name-crash.cpp b/test/SemaCXX/injected-class-name-crash.cpp
new file mode 100644
index 0000000000..2996a7cdb4
--- /dev/null
+++ b/test/SemaCXX/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() {
+}