Bug 396339 - Extract Function passes pointer parameters but assigns as integer
Summary: Extract Function passes pointer parameters but assigns as integer
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:22 EST by Farnaz Behrang CLA
Modified: 2020-09-04 15:17 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:22:52 EST
In the following program...

==========
#define c 5;
int main(){
  int i,k,r;
  k = i + 1; /* << extract these */
  r = k*c;   /* << two lines */		
  printf("%d",k);
  printf("%d",r);
  return 0;
}
==========

...if you select lines 4 and 5 and invoke the Extract Function refactoring, CDT produces the following incorrect code:

==========
#define c 5;
int extracted_function(int k, int i, int* r) {
	k = i + 1;
	r = k * c
	;
	return k;
}

int main() {
  int i,k,r;
   k = extracted_function(k, i, &r);
  printf("%d",k);
  printf("%d",r);
  return 0;
}
==========

In the expected function, the assignment should be to *r, not to r, since r is being passed to a pointer. I would expect the extraction would be as follows:

==========
#define c 5;

int extracted_function(int k, int i, int* r) {
	k = i + 1;
	*r = k * c;
	return k;
}

int main() {
  int i,k,r;
  k = extracted_function(k, i, &r);
  printf("%d",k);
  printf("%d",r);
  return 0;
}

==========