From 59d0d7461d22cc832c228fa887a79376186a8ffb Mon Sep 17 00:00:00 2001 From: Serge Pavlov Date: Mon, 28 Dec 2015 19:40:14 +0000 Subject: [PATCH] Do not crash if class is defined in wrong scope. This patch fixes PR16677. The latter represents the case when due to misprinted character class definition occurs in the scope of template arguments. Base class of this class depends on the template parameter in the same scope and cannot be resolved, it causes crash. Right behavior is to make semantic processing even if the definition is wrong, as the code that emits appropriate message is called after the processing. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@256511 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaDeclCXX.cpp | 4 +++- test/SemaCXX/PR16677.cpp | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 test/SemaCXX/PR16677.cpp diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index cdfdc37f5e..9cd3002dd8 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -5626,7 +5626,9 @@ bool SpecialMemberDeletionInfo::shouldDeleteForClassSubobject( /// having a particular direct or virtual base class. bool SpecialMemberDeletionInfo::shouldDeleteForBase(CXXBaseSpecifier *Base) { CXXRecordDecl *BaseClass = Base->getType()->getAsCXXRecordDecl(); - return shouldDeleteForClassSubobject(BaseClass, Base, 0); + // If program is correct, BaseClass cannot be null, but if it is, the error + // must be reported elsewhere. + return BaseClass && shouldDeleteForClassSubobject(BaseClass, Base, 0); } /// Check whether we should delete a special member function due to the class diff --git a/test/SemaCXX/PR16677.cpp b/test/SemaCXX/PR16677.cpp new file mode 100644 index 0000000000..7140ac79f0 --- /dev/null +++ b/test/SemaCXX/PR16677.cpp @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s + +class Class_With_Destructor { + ~Class_With_Destructor() { } +}; + +template +class Base { }; + +template { // expected-error{{'Derived' cannot be defined in a type specifier}} + Class_With_Destructor member; +}; // expected-error{{a non-type template parameter cannot have type 'class Derived'}} + // expected-error@-1{{expected ',' or '>' in template-parameter-list}} + // expected-warning@-2{{declaration does not declare anything}} + -- 2.40.0