>
> Patch looks good. Could you provide a test case that we can integrate into
> Clang's test suite, e.g., that extends test/SemaCXX/new-delete.cpp?
>
Done.
> > If someone could point out how to turn the QualType instance representing
> 'Foo *' into just 'Foo', I'd appreciate it.
>
>
> Isn't PointeeElem the type you want to print?
>
> In any case, if you want to dig out the type that a QualType T points to,
> use something like
>
> if (const PointerType *PointerT = T->getAs<PointerType>()) {
> // PointerT->getPointeeType() is the type that T points to
> }
>
Thanks for pointing out that PointeeElem already held the right type. Fixed.
>
> Could you re-submit the patch with those tweaks? Thanks for working on
> this!
>
> - Doug
Attached and no problem! :)
Thanks,
Alex
Index: test/SemaCXX/new-delete.cpp
===================================================================
--- test/SemaCXX/new-delete.cpp (revision 124614)
+++ test/SemaCXX/new-delete.cpp (working copy)
@@ -234,6 +234,17 @@
delete x14a;
}
+class X15 {
+private:
+ X15(); // expected-note {{declared private here}}
+ ~X15(); // expected-note {{declared private here}}
+};
+
+void f(X15* x) {
+ new X15(); // expected-error {{calling a private constructor}}
+ delete x; // expected-error {{calling a private destructor}}
+}
+
namespace PR5918 { // Look for template operator new overloads.
struct S { template<typename T> static void* operator new(size_t, T); };
void test() {
Index: include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- include/clang/Basic/DiagnosticSemaKinds.td (revision 124614)
+++ include/clang/Basic/DiagnosticSemaKinds.td (working copy)
@@ -564,6 +564,8 @@
def err_access_ctor_field :
Error<"field of type %1 has %select{private|protected}2 constructor">,
AccessControl;
+def err_access_dtor : Error<
+ "calling a %select{private|protected}1 destructor of class %0">, NoSFINAE;
def err_access_dtor_base :
Error<"base class %0 has %select{private|protected}1 destructor">,
AccessControl;
Index: lib/Sema/SemaExprCXX.cpp
===================================================================
--- lib/Sema/SemaExprCXX.cpp (revision 124614)
+++ lib/Sema/SemaExprCXX.cpp (working copy)
@@ -1687,7 +1687,15 @@
MarkDeclarationReferenced(StartLoc, OperatorDelete);
- // FIXME: Check access and ambiguity of operator delete and destructor.
+ // Check access and ambiguity of operator delete and destructor.
+ if (const RecordType *RT = PointeeElem->getAs<RecordType>()) {
+ CXXRecordDecl *RD = cast<CXXRecordDecl>(RT->getDecl());
+ if (CXXDestructorDecl *Dtor = LookupDestructor(RD)) {
+ CheckDestructorAccess(Ex->getExprLoc(), Dtor,
+ PDiag(diag::err_access_dtor) << PointeeElem);
+ }
+ }
+
}
return Owned(new (Context) CXXDeleteExpr(Context.VoidTy, UseGlobal, ArrayForm,
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits