[cfe-commits] r152519 - in /cfe/trunk: lib/Sema/SemaExprCXX.cpp test/CXX/expr/expr.unary/expr.new/p17-crash.cpp test/CXX/expr/expr.unary/expr.new/p17.cpp
David Blaikie
dblaikie at gmail.com
Sat Mar 10 15:40:03 PST 2012
Author: dblaikie
Date: Sat Mar 10 17:40:02 2012
New Revision: 152519
URL: http://llvm.org/viewvc/llvm-project?rev=152519&view=rev
Log:
Fix crash & accepts-invalid for array of arrays of user defined type.
Test case/other help by Richard Smith.
Code review by John McCall.
Added:
cfe/trunk/test/CXX/expr/expr.unary/expr.new/p17-crash.cpp
cfe/trunk/test/CXX/expr/expr.unary/expr.new/p17.cpp
Modified:
cfe/trunk/lib/Sema/SemaExprCXX.cpp
Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=152519&r1=152518&r2=152519&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Sat Mar 10 17:40:02 2012
@@ -1330,14 +1330,17 @@
// C++0x [expr.new]p17:
// If the new expression creates an array of objects of class type,
// access and ambiguity control are done for the destructor.
- if (ArraySize && AllocType->isRecordType() && !AllocType->isDependentType()) {
- if (CXXDestructorDecl *dtor = LookupDestructor(
- cast<CXXRecordDecl>(AllocType->getAs<RecordType>()->getDecl()))) {
- MarkFunctionReferenced(StartLoc, dtor);
- CheckDestructorAccess(StartLoc, dtor,
- PDiag(diag::err_access_dtor)
- << Context.getBaseElementType(AllocType));
- DiagnoseUseOfDecl(dtor, StartLoc);
+ QualType BaseAllocType = Context.getBaseElementType(AllocType);
+ if (ArraySize && !BaseAllocType->isDependentType()) {
+ if (const RecordType *BaseRecordType = BaseAllocType->getAs<RecordType>()) {
+ if (CXXDestructorDecl *dtor = LookupDestructor(
+ cast<CXXRecordDecl>(BaseRecordType->getDecl()))) {
+ MarkFunctionReferenced(StartLoc, dtor);
+ CheckDestructorAccess(StartLoc, dtor,
+ PDiag(diag::err_access_dtor)
+ << BaseAllocType);
+ DiagnoseUseOfDecl(dtor, StartLoc);
+ }
}
}
Added: cfe/trunk/test/CXX/expr/expr.unary/expr.new/p17-crash.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/expr/expr.unary/expr.new/p17-crash.cpp?rev=152519&view=auto
==============================================================================
--- cfe/trunk/test/CXX/expr/expr.unary/expr.new/p17-crash.cpp (added)
+++ cfe/trunk/test/CXX/expr/expr.unary/expr.new/p17-crash.cpp Sat Mar 10 17:40:02 2012
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -emit-llvm-only %s
+
+// this used to crash due to templ<int>'s dtor not being marked as used by the
+// new expression in func()
+struct non_trivial {
+ non_trivial() {}
+ ~non_trivial() {}
+};
+template < typename T > class templ {
+ non_trivial n;
+};
+void func() {
+ new templ<int>[1][1];
+}
Added: cfe/trunk/test/CXX/expr/expr.unary/expr.new/p17.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/expr/expr.unary/expr.new/p17.cpp?rev=152519&view=auto
==============================================================================
--- cfe/trunk/test/CXX/expr/expr.unary/expr.new/p17.cpp (added)
+++ cfe/trunk/test/CXX/expr/expr.unary/expr.new/p17.cpp Sat Mar 10 17:40:02 2012
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+class ctor {
+ ctor(); // expected-note{{implicitly declared private here}}
+};
+
+class dtor {
+ ~dtor(); // expected-note 3 {{implicitly declared private here}}
+};
+
+void test() {
+ new ctor[0]; // expected-error{{calling a private constructor of class 'ctor'}}
+ new dtor[0]; // expected-error{{calling a private destructor of class 'dtor'}}
+ new dtor[3]; // expected-error{{calling a private destructor of class 'dtor'}}
+ new dtor[3][3]; // expected-error{{calling a private destructor of class 'dtor'}}
+}
More information about the cfe-commits
mailing list