Bug 425444 - Compilation error when extracting variable with an existing name
Summary: Compilation error when extracting variable with an existing name
Status: NEW
Alias: None
Product: CDT
Classification: Tools
Component: cdt-refactoring (show other bugs)
Version: Next   Edit
Hardware: PC 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: 2014-01-10 14:24 EST by Gustavo Wagner CLA
Modified: 2020-09-04 15:18 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Gustavo Wagner CLA 2014-01-10 14:24:59 EST
Eclipse IDE for C/C++ Developers
Version: Kepler Service Release 1
Build id: 20130919-0819


Reproducing the bug:


Consider the following code:
============== Original Version ===============
int main(int a, char** argv) {
    int b = 0; // Constant to be extracted to a variable
    return 0;
}
===============================================

Now, choosing an existing name to the the extracted variable, the refactoring tool allows the following transformation:

============== Original Version ===============
int main(int a, char** argv) {
    int a = 0; // Declaring an existing declaration (parameter "a")
    int b = a;
    return 0;
}
===============================================

The resulting code has a semantic error (multiple declaration in the same scope). I guess an alternative would be checking all declarations to avoid this kind of problem (considering also global declarations to prevent shadowing a global variable in the local scope).


Thanks in advance.
Comment 1 Gustavo Wagner CLA 2014-01-11 00:20:01 EST
* by constant, I was actually saying "literal value"

Sorry about that.