Commit 0038e827 authored by Libor Tomsik's avatar Libor Tomsik

Refactor: Comment out delete statement of heap variables

Convert to Stack Variable generates crashing code.

Task-number: QTCREATORBUG-13685
Change-Id: I4555de223e50bc8d75e97205d273aa0f09f652fc
Reviewed-by: Orgad Shaneh's avatarOrgad Shaneh <orgads@gmail.com>
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@theqtcompany.com>
parent 07e9c441
......@@ -1471,6 +1471,23 @@ void CppEditorPlugin::test_quickfix_data()
" str.clear();\n"
"}\n");
QTest::newRow("ConvertFromPointer_structWithPointer")
<< CppQuickFixFactoryPtr(new ConvertFromAndToPointer)
<< _("struct Bar{ QString *str; };\n"
"void foo() {\n"
" Bar *@bar = new Bar;\n"
" bar->str = new QString;\n"
" delete bar->str;\n"
" delete bar;\n"
"}\n")
<< _("struct Bar{ QString *str; };\n"
"void foo() {\n"
" Bar bar;\n"
" bar.str = new QString;\n"
" delete bar.str;\n"
" // delete bar;\n"
"}\n");
QTest::newRow("ConvertToPointer_withInitializer")
<< CppQuickFixFactoryPtr(new ConvertFromAndToPointer)
<< _("void foo() {\n"
......
......@@ -4077,6 +4077,8 @@ private:
bool starFound = false;
int ampersandPos = 0;
bool memberAccess = false;
bool deleteCall = false;
for (int i = path.count() - 2; i >= 0; --i) {
if (path.at(i) == m_declaratorAST) {
declarationFound = true;
......@@ -4089,6 +4091,11 @@ private:
changes.replace(pos, pos + 2, QLatin1String("."));
memberAccess = true;
break;
} else if (DeleteExpressionAST *deleteAST = path.at(i)->asDeleteExpression()) {
const int pos = m_file->startOf(deleteAST->delete_token);
changes.insert(pos, QLatin1String("// "));
deleteCall = true;
break;
} else if (UnaryExpressionAST *unaryExprAST = path.at(i)->asUnaryExpression()) {
const Token tk = m_file->tokenAt(unaryExprAST->unary_op_token);
if (tk.kind() == T_STAR) {
......@@ -4110,7 +4117,7 @@ private:
break;
}
}
if (!declarationFound && !starFound && !memberAccess) {
if (!declarationFound && !starFound && !memberAccess && !deleteCall) {
if (ampersandPos) {
changes.insert(ampersandPos, QLatin1String("&("));
changes.insert(m_file->endOf(idAST->firstToken()), QLatin1String(")"));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment