Community
Participate
Working Groups
Build Identifier: I20110613-1736 After for statement with braces on level of identation is lost and code is ill-formatted from there on. Reproducible: Always Steps to Reproduce: 1. Crate C project, add new C source file. You can use this code: void foo() { int i; for (i = 0; i < 10; i++) { } foo(); } 2. Go to preferences, C/C++, Code style, and select GNU or Whitesmiths. Select source, do Source/Format. 3. For GNU you get: void foo() { int i; for (i = 0; i < 10; i++) { } foo(); } (Notice that function call is not idented.)
The problem seems to be with the for loop. The closing brace should be aligned with the opening one. This does work with 7.0.2, so it's a regression.
Hi there. I too have been experiencing problems with the code formatter in this new version of Eclipse CDT (8.0, build ID 20110615-0604). These problems do not occur in the previous version of Eclipse CDT (7.0.2). In order to reproduce the problem, just create a new C++ project and create a single CPP file as follows: #include <iostream> using namespace std; long function() { cout << "From function" << endl; } class Foo { public: Foo(); ~Foo(); void SayHello() const; }; int main() { Foo * foo = new Foo(); int i = static_cast<int>(5); foo->SayHello(); return 0; } If you select the BSD/Allman built-in formatting profile and format the code above, everything is fine, and it is displayed just as I just showed you. However, if we change the expression inside the static_cast to a call to 'function()', the line right after it gets messed up, and we get: int main() { Foo * foo = new Foo(); int i = static_cast<int>(function()); foo ->SayHello(); return 0; } This problem also occurs if the expression inside the static_cast is an arithmetic operation, such as '5 * 6' or '4 + 5'. I tried to copy and paste the static_cast all over the main() function, and it seems that only the line right after it gets corrupted. Everything afterwards is properly formatted. Looks like the problem arises when whatever is inside the static_cast is different from a simple identifier or constant.
(In reply to comment #2) > I too have been experiencing problems with the code formatter in this new > version of Eclipse CDT (8.0, build ID 20110615-0604). These problems do not > occur in the previous version of Eclipse CDT (7.0.2). Please create a separate bug for this problem. Thanks!
Fixed in master and 8.0.1.
*** cdt git genie on behalf of Anton Leherbauer *** Bug 351399 - Formatting C code is broken for certain coding styles [*] http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=44e3ec0cde0a4961628c4d35f23f704c398be6b2
*** cdt git genie on behalf of Anton Leherbauer *** Bug 351399 - Formatting C code is broken for certain coding styles [*] http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=2d8f61dc4fa595d458623b4cd607ad6373bb068b
*** Bug 357040 has been marked as a duplicate of this bug. ***