Bug 396343 - Extract Function incorrectly extracts constant values used in pointer comparisons
Summary: Extract Function incorrectly extracts constant values used in pointer compari...
Status: NEW
Alias: None
Product: CDT
Classification: Tools
Component: cdt-refactoring (show other bugs)
Version: 8.1.1   Edit
Hardware: PC Linux
: P3 minor (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact: Jonah Graham CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-12-11 17:35 EST by Farnaz Behrang CLA
Modified: 2020-09-04 15:24 EDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Farnaz Behrang CLA 2012-12-11 17:35:04 EST
In the following program...

==========
int main(){
 void* a;
 int b;
 if (a!= 0) //extract 0 
     b=0;
 return 0;
}
==========

...if you select 0 (on line 4) and invoke the Extract Function refactoring, CDT produces the following code:
==========
int extracted_function() {
  return 0;
}
int main() {
 void* a;
 int b;
 if (a != extracted_function())
     b=0;
return 0;
}
==========

After the refactoring there would be a comparison between pointer and integer. So, I would expect that this would be disallowed, or it would extract a function that returns a pointer, as follows: 

==========
int* extracted_function() {
  return 0;
}
int main() {
 void* a;
 int b;
 if (a != extracted_function())
     b=0;
return 0;
}
==========