[cfe-commits] [PATCH] Check access and ambiguity of delete operator
Douglas Gregor
dgregor at apple.com
Mon Jan 24 10:25:03 PST 2011
On Jan 21, 2011, at 4:39 PM, Alex Miller wrote:
> The attached patch should fix the TODO at lib/Sema/SemaExprCXX.cpp:1610
>
> When compiling the following code
>
> class Foo {
> private:
> ~Foo();
> };
>
> void do_foo() {
> Foo *f = new Foo;
> delete f;
> }
>
> clang now emits the error
>
> testcase.cpp:8:10: error: calling a private destructor of class 'Foo *'
> delete f;
> ^
> testcase.cpp:3:5: note: declared private here
> ~Foo();
> ^
> 1 error generated.
>
> instead of compiling the code successfully.
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?
> 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
}
Could you re-submit the patch with those tweaks? Thanks for working on this!
- Doug
More information about the cfe-commits
mailing list