Skip to content

Commit

Permalink
Merging r251335:
Browse files Browse the repository at this point in the history
------------------------------------------------------------------------
r251335 | ismail.pazarbasi | 2015-10-26 15:20:24 -0400 (Mon, 26 Oct 2015) | 13 lines

MismatchingNewDeleteDetector uses incorrect field, and finds no initializer

Summary:
In `MismatchingNewDeleteDetector::analyzeInClassInitializer`, if
`Field`'s initializer expression is null, lookup the field in
implicit instantiation, and use found field's the initializer.

Reviewers: rsmith, rtrieu

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D9898

------------------------------------------------------------------------

llvm-svn: 252290
  • Loading branch information
tstellarAMD committed Nov 6, 2015
1 parent 4556303 commit 832552a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
6 changes: 4 additions & 2 deletions clang/lib/Sema/SemaExprCXX.cpp
Expand Up @@ -2485,8 +2485,10 @@ bool MismatchingNewDeleteDetector::hasMatchingNewInCtor(
MismatchingNewDeleteDetector::MismatchResult
MismatchingNewDeleteDetector::analyzeInClassInitializer() {
assert(Field != nullptr && "This should be called only for members");
if (const CXXNewExpr *NE =
getNewExprFromInitListOrExpr(Field->getInClassInitializer())) {
const Expr *InitExpr = Field->getInClassInitializer();
if (!InitExpr)
return EndOfTU ? NoMismatch : AnalyzeLater;
if (const CXXNewExpr *NE = getNewExprFromInitListOrExpr(InitExpr)) {
if (NE->isArray() != IsArrayForm) {
NewExprs.push_back(NE);
return MemberInitMismatches;
Expand Down
16 changes: 16 additions & 0 deletions clang/test/SemaCXX/delete.cpp
Expand Up @@ -120,6 +120,22 @@ void f() {
DELETE(d); // expected-warning {{'delete' applied to a pointer that was allocated with 'new[]'; did you mean 'delete[]'?}}
}
}

namespace MissingInitializer {
template<typename T>
struct Base {
struct S {
const T *p1 = nullptr;
const T *p2 = new T[3];
};
};

void null_init(Base<double>::S s) {
delete s.p1;
delete s.p2;
}
}

#ifndef WITH_PCH
pch_test::X::X()
: a(new int[1]) // expected-note{{allocated with 'new[]' here}}
Expand Down

0 comments on commit 832552a

Please sign in to comment.