Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
 All Forums
 Visual Assist
 Technical Support
 "Extract method" produces incorrect code

You must be registered to post a reply.
Click here to register.

Screensize:
UserName:
Password:
Format: BoldItalicizeUnderlineStrikethrough Align leftCenterAlign right Insert horizontal ruleUpload and insert imageInsert hyperlinkInsert email addressInsert codeInsert quoted textInsert listInsert Emoji
   
Message:

Forum code is on.
Html is off.

 
Check to subscribe to this topic.
   

T O P I C    R E V I E W
MichaelH Posted - Sep 27 2018 : 05:34:01 AM
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

1   L A T E S T    R E P L I E S    (Newest First)
feline Posted - Sep 27 2018 : 5:13:49 PM
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.

© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000