Community
Participate
Working Groups
Build Identifier: 7.0.0.201005161106 Trying to rename a local variable with the va_list type (from stdarg.h) results in a "global function" rename operation, where all variables with that name being part of the rename target. Reproducible: Always Steps to Reproduce: 1. create a new C++ source file with this code: #include <stdarg.h> #include <stdio.h> void foo(const char* name, ...) { va_list result; va_start(result, name); printf("%d\n", (intptr_t)(va_arg(result, intptr_t))); va_end(result); } int main() { foo("number", 2, 3, 4); } void bar() { int result = 1; printf("%d\n", result); } 2. select the result variable in function foo() 3. hit alt+shift+r, enter "result2" for the new name, press enter to preview 4. press enter to continue result: in the changes to be performed, it includes both the local variables in the foo() and the bar() functions both named result. in a large project, this resulted in hundreds of candidates. expected result: should only see the local variable's context as candidate for the rename refactoring.
This works for me, please provide a parser log for the file: Context menu of file in project explorer - Index - Create Parser Log.
attached the parser log for the code below. odd that the log says it can't resolve printf and intptr_t -- I can control click on them, and they go to the correct header files that are explicitly included. re-ordering the header includes doesn't fix that problem. Note that this is on Ubuntu 10.04, x86-64. I just installed the latest CDT build (201005191123) and still get the same results. #include <stdarg.h> #include <stdint.h> #include <stdio.h> void foo(const char* name, ...) { va_list result; va_start(result, name); printf("%d\n", (intptr_t)(va_arg(result, intptr_t))); va_end(result); } int main() { foo("number", 2, 3, 4); } void bar() { int result = 1; printf("%d\n", result); }
Created attachment 169243 [details] parser log for code with issue
(In reply to comment #3) > Created an attachment (id=169243) [details] > parser log for code with issue From the parser log it looks like the parser does not know 'intptr_t'. But even with that the rename works for me. To figure out what causes the issue, please try to do the refactoring with the self contained code below (it should work). Then replace e.g. 'typedef int intptr_t' with '#include <stdint.h>' or with whatever you find in stdint.h and check again. // self contained example. typedef int intptr_t; int printf (const char*, ...); void foo(const char* name, ...) { __builtin_va_list result; __builtin_va_start(result, name); printf("%d\n", (intptr_t)(__builtin_va_arg(result, intptr_t))); __builtin_va_end(result); } int main() { foo("number", 2, 3, 4); } void bar() { int result = 1; printf("%d\n", result); }
With a brand new, empty project, it works. In my cgreen project, it doesn't. I'm attaching an archive of the cgreen project. The eclipse project file (as generated by CMake) is src/cgreen-build/.project.
Created attachment 169565 [details] my eclipse project where renaming a function local va_list variable does a global function rename instead
Thanks, I can reproduce the issue.
Created attachment 169942 [details] testcase + fix
Fixed in 7.0 > 20100526.
[CDT Genie] changed http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt-core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/GCCBuiltinSymbolProvider.java?root=Tools_Project&r1=1.27&r2=1.28
*** cdt cvs genie on behalf of mschorn *** [!] AST2Tests.java 1.258 http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt-core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java?root=Tools_Project&r1=1.257&r2=1.258