cpp11-migrate segfaults transforming map<string,int>::iterator

cpp11-migrate segfaults when -use-auto tries to resolve initializing 
expression resulting in an expression with cleanups.

- Skip expressions with cleanups from the initializer
- Added test case

Fixes PR15550

llvm-svn: 178167
This commit is contained in:
Ariel J. Bernal 2013-03-27 18:49:31 +00:00
parent 38a723830c
commit 3f08aae84f
3 changed files with 19 additions and 1 deletions

View File

@ -28,7 +28,14 @@ void UseAutoFixer::run(const MatchFinder::MatchResult &Result) {
if (!SM.isFromMainFile(D->getLocStart()))
return;
const CXXConstructExpr *Construct = cast<CXXConstructExpr>(D->getInit());
const Expr *ExprInit = D->getInit();
// Skip expressions with cleanups from the initializer expression.
if (const ExprWithCleanups *E = dyn_cast<ExprWithCleanups>(ExprInit))
ExprInit = E->getSubExpr();
const CXXConstructExpr *Construct = cast<CXXConstructExpr>(ExprInit);
assert(Construct->getNumArgs() == 1u &&
"Expected constructor with single argument");

View File

@ -107,6 +107,9 @@ public:
const_reverse_iterator rbegin() const { return const_reverse_iterator(); }
const_reverse_iterator rend() const { return const_reverse_iterator(); }
template <typename K>
iterator find(const K &Key) { return iterator(); }
};
#if USE_INLINE_NAMESPACE

View File

@ -148,5 +148,13 @@ int main(int argc, char **argv) {
// CHECK: auto && I2 = Vec.begin();
}
// Passing a string as an argument to introduce a temporary object
// that will create an expression with cleanups. Bugzilla: 15550
{
std::unordered_map<int> MapFind;
std::unordered_map<int>::iterator I = MapFind.find("foo");
// CHECK: auto I = MapFind.find("foo");
}
return 0;
}