Bug 425446 - Compilation error when extracting a define to a local variable
Summary: Compilation error when extracting a define to a local variable
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:58 EST by Gustavo Wagner CLA
Modified: 2020-09-04 15:27 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:58:56 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 C =3;

int main(int a, char** argv) {
    int b C // Macro to be extracted
    printf ("%d\n",b);
    return 0;
}
===============================================

After applying the refactoring, we have the resulting code:
============= Refactored Version ==============
#define C =3;

int main(int a, char** argv) {
    int i = C; // Extracted macro
    int b i
    printf ("%d\n",b);
    return 0;
}
===============================================

When expanding the macro C, the extracted line will result in "int i = =3" (syntax error).

I believe it's tricky to check constraints of a transformation when there's a macro involved, since its semantics is unknown (in this case, it is an assignment but it could be a constant, a function, and so on). However, an option could be a warning to the user about the resulting transformation ("Am I aware of what I'm trying to do?"). Another option could be even trying to check if the macro definition won't cause problems in the transformation.


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

Sorry about that.