Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
User name:
Password:
Save Password
Forgot your password?

 All Forums
 Visual Assist
 Technical Support
 "Extract method" produces incorrect code
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

MichaelH
Junior Member

10 Posts

Posted - Sep 27 2018 :  05:34:01 AM  Show Profile  Reply with Quote
Using the following (simple) example:

class Foo
{
  public:
    Foo() { value = 0; };
    Foo& operator<<(const Foo&) { value++;  return *this; };
    int value;
};

void doFoo()
{
    Foo f;
    f << Foo();
    f << Foo();
    //f.value == 2
}

//After "Extract Method" refactoring:
//MyMethod should either take a (Foo& f) or possibly return a Foo (if Foo supports the assignment operator)
void MyMethod(Foo f) 
{
    f << Foo();
}

void doFooAfterExtractMethod()
{
    Foo f;
    MyMethod(f);
    MyMethod(f);
    //f.value == 0
}


I (fortunately) noticed because the orignal class (QTextStream) does not have a copy constructor (QTextStream(const QTextStream&) = delete) - can you check why the refactoring produces incorrect code in this case?

System Info:
Visual Studio 2015 Update 3, C++
License: [email protected] (2-user license) Support ends 2019.06.14
VA_X.dll file version 10.9.2283.2 built 2018.08.02
DevEnv.exe version 14.0.25420.1 Professional
msenv.dll version 14.0.25431.1
Comctl32.dll version 6.10.17134.285
Windows 10 10.0 Build 17134.285
8 processors (x86-64, WOW64)
Language info: 1252, 0x407


Edited by - MichaelH on Sep 27 2018 06:16:11 AM

feline
Whole Tomato Software

United Kingdom
18749 Posts

Posted - Sep 27 2018 :  5:13:49 PM  Show Profile  Reply with Quote
I am seeing the same effect here. Thank you for the clear description.

case=119662

I think the basic problem here is that VA does not realise the variable is being modified when being on the left hand side of the overloaded << function. Still, getting the wrong behaviour from Extract Method is fairly serious.

zen is the art of being at one with the two'ness
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000