Bug 397278 - [Refactoring] Extract local variable refactoring allows to define a new variable with a name of an existent variable
Summary: [Refactoring] Extract local variable refactoring allows to define a new varia...
Status: NEW
Alias: None
Product: CDT
Classification: Tools
Component: cdt-refactoring (show other bugs)
Version: 8.1.1   Edit
Hardware: Macintosh Mac OS X
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact: Jonah Graham CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-12-31 13:17 EST by Gustavo Wagner CLA
Modified: 2020-09-04 15:25 EDT (History)
3 users (show)

See Also:


Attachments
Minimal project to verify the problem (1.92 KB, application/x-zip-compressed)
2013-02-05 14:55 EST, Jesse Weinstein CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Gustavo Wagner CLA 2012-12-31 13:17:51 EST
Version: Juno Service Release 1
Build id: 20120920-0800

CDT refactoring allows to extract local variable with a name of an existent global variable, leading to a behavioral change.

Reproducible: Always

Steps to Reproduce:

1. Create a C file with the following code:

#include <stdio.h>

int y = 20;

int main(){
    int x = 10; //extract local variable
    printf("%d", y);
    return 0;
}


//output: 20


2. Select "10" literal and apply the Extract Local Variable refactoring typing "y" in the
Variable Name (CDT silently do that):


#include <stdio.h>

int main(){
     int y = 10;
     int x = y;
     printf("%d", y);
     return 0;
}

//output: 10

3. The program change its output from 20 to 10.
Comment 1 Jesse Weinstein CLA 2013-02-05 14:55:48 EST
Created attachment 226587 [details]
Minimal project to verify the problem

I've verified (a slightly modified version of) this using eclipse-SDK-N20130203-2000-win32 with org.eclipse.cdt_8.2.0.201212170456 . Here's the project, to make it easier for other people to verify it.

In order to avoid the need for an #include, I changed the code to:

int y = 20;

int main(){
    int x = 10; //extract local variable
    return y;
}

The problem still shows up in the same way.