Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 360149

Summary: Cannot extract variable if one of the function arguments is macro expansion.
Product: [Tools] CDT Reporter: Eugene Ostroukhov <eostroukhov>
Component: cdt-refactoringAssignee: Sergey Prigogin <eclipse.sprigogin>
Status: RESOLVED FIXED QA Contact: Sergey Prigogin <eclipse.sprigogin>
Severity: normal    
Priority: P3 CC: cdtdoug, yevshif
Version: 8.0   
Target Milestone: 8.1.0   
Hardware: PC   
OS: Linux   
Whiteboard:
Attachments:
Description Flags
Suggested fix cdtdoug: iplog+

Description Eugene Ostroukhov CLA 2011-10-06 14:39:43 EDT
Created attachment 204703 [details]
Suggested fix

Assume following source code:
1 #define BLOCKS 32
2 
3 void myfunction(int a) {}
4 void myfunction(int a, int b) {}
5 
6 void deviceFindMax() {
7 	myfunction(1, BLOCKS);
8 }

On the line 7 select "1" and do "Extract Local Variable". Enter some variable name and proceed to second wizard page. Note that variable declaration is introduced but line 7 was not changed.

In the editor change line 7 to:
7 	myfunction(1);

Verify that 1 can be extracted as expected.

This issue is caused by ASTWriterVisitor detecting that statement has macro expansion (see condition in public int visit(IASTStatement statement)) and copying statement text from the original code without applying any modification.

I do not understand what this code is for hence attached patch is most likely wrong. I would be glad to work more on fixing this issue if somebody could provide me more scenarios to test.
Comment 1 Sergey Prigogin CLA 2011-12-14 15:30:16 EST
Fixed together with bug 363244.