diff options
| author | John McCall <rjmccall@apple.com> | 2010-08-04 00:31:26 +0000 |
|---|---|---|
| committer | John McCall <rjmccall@apple.com> | 2010-08-04 00:31:26 +0000 |
| commit | 66a8759400a96640b66b83f1acc53e37a7713fed (patch) | |
| tree | 06be5354f852037cae91fef60c33d6ccef004dc3 /clang/lib/Sema/SemaExprCXX.cpp | |
| parent | 4f9c40c5214a252def0611ec44b513d909106569 (diff) | |
| download | bcm5719-llvm-66a8759400a96640b66b83f1acc53e37a7713fed.tar.gz bcm5719-llvm-66a8759400a96640b66b83f1acc53e37a7713fed.zip | |
Look through using declarations when deciding whether to use an operator
delete for a virtual destructor. Diagnose ambiguities.
Fixes PR7803.
llvm-svn: 110173
Diffstat (limited to 'clang/lib/Sema/SemaExprCXX.cpp')
| -rw-r--r-- | clang/lib/Sema/SemaExprCXX.cpp | 37 |
1 files changed, 26 insertions, 11 deletions
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp index 8b2fc7e56a1..6d28dbdc12a 100644 --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -1298,15 +1298,31 @@ bool Sema::FindDeallocationFunction(SourceLocation StartLoc, CXXRecordDecl *RD, Found.suppressDiagnostics(); + llvm::SmallVector<DeclAccessPair,4> Matches; for (LookupResult::iterator F = Found.begin(), FEnd = Found.end(); F != FEnd; ++F) { - if (CXXMethodDecl *Delete = dyn_cast<CXXMethodDecl>(*F)) - if (Delete->isUsualDeallocationFunction()) { - Operator = Delete; - CheckAllocationAccess(StartLoc, SourceRange(), Found.getNamingClass(), - F.getPair()); - return false; - } + CXXMethodDecl *Delete = cast<CXXMethodDecl>((*F)->getUnderlyingDecl()); + if (Delete->isUsualDeallocationFunction()) + Matches.push_back(F.getPair()); + } + + // There's exactly one suitable operator; pick it. + if (Matches.size() == 1) { + Operator = cast<CXXMethodDecl>(Matches[0]->getUnderlyingDecl()); + CheckAllocationAccess(StartLoc, SourceRange(), Found.getNamingClass(), + Matches[0]); + return false; + + // We found multiple suitable operators; complain about the ambiguity. + } else if (!Matches.empty()) { + Diag(StartLoc, diag::err_ambiguous_suitable_delete_member_function_found) + << Name << RD; + + for (llvm::SmallVectorImpl<DeclAccessPair>::iterator + F = Matches.begin(), FEnd = Matches.end(); F != FEnd; ++F) + Diag((*F)->getUnderlyingDecl()->getLocation(), + diag::note_member_declared_here) << Name; + return true; } // We did find operator delete/operator delete[] declarations, but @@ -1316,10 +1332,9 @@ bool Sema::FindDeallocationFunction(SourceLocation StartLoc, CXXRecordDecl *RD, << Name << RD; for (LookupResult::iterator F = Found.begin(), FEnd = Found.end(); - F != FEnd; ++F) { - Diag((*F)->getLocation(), diag::note_member_declared_here) - << Name; - } + F != FEnd; ++F) + Diag((*F)->getUnderlyingDecl()->getLocation(), + diag::note_member_declared_here) << Name; return true; } |

