Details
-
Bug
-
Resolution: Unresolved
-
Not Evaluated
-
None
-
Qt Creator 15.0.0-beta1
Description
The refactoring method: "Extract Function" does not respect possible modifications of members of the to be extracted code.
#include <QDebug> #include <QVector> class A { public: int i() const; void setI(int newI); private: int _i; }; int A::i() const { return _i; } void A::setI(int newI) { _i = newI; } int main() { A a1; // extract next three lines to a function. a1.setI(2); a1.setI(3); a1.setI(4); qDebug() << a1.i(); }
When extracting the next the marked lines in main() to an external function via the
Refactor => Extract Function
the resulting method looks like this:
void modify(A a1)
{
a1.setI(2);
a1.setI(3);
a1.setI(4);
}
int main()
{
A a1;
modify(a1);
qDebug() << a1.i();
}
As modify gets the parameter as copy the modification will be applied to the local a1.
The a1 in the main() will not be modified.
btw: using the refactoring "Clang: Extract to function" give a working result:
void extracted(A &a1) {
a1.setI(2);
a1.setI(3);
a1.setI(4);
}
int main() {
A a1;
extracted(a1);
qDebug() << a1.i();
}
"extracted" gets a1 as reference and so the changes will be relevant in main().