Bug 426915 - [Refactoring] Extracting function to a memory reference shouldn't be allowed
Summary: [Refactoring] Extracting function to a memory reference shouldn't be allowed
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-29 11:15 EST by Gustavo Wagner CLA
Modified: 2020-09-04 15:21 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-29 11:15:03 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 ========
#define Id_0

void func_0() {
    float LocalVar_0 = 10;
    #ifdef Id_0
        LocalVar_0 = -1;
    #endif
}

void Function_0(float LocalVar_1) {
    float LocalVar_0 = 0;
    LocalVar_0 = -1;
}
==================================

Now, let's the extract a function named "&old"
Applying the refactoring:
========== Refactored ============
#define Id_0

int &old() {
    return 10;
}
void func_0() {
    float LocalVar_0 = &old();
    #ifdef Id_0
        LocalVar_0 = -1;
    #endif
}

void Function_0(float LocalVar_1) {
    float LocalVar_0 = 0;
    LocalVar_0 = -1;
}
=================================

The tool shouldn't allow to apply invalid transformations like this. Notice that now the program has a compilation error. It would be good if it was possible to prevent incorrect extractions at least by checking if new function has a valid name.

Thanks in advance.
Comment 1 Gustavo Wagner CLA 2014-01-29 11:48:10 EST
Correcting:
* Now, let's extract a function named "&old"