Community
Participate
Working Groups
We have a problem with formatting C++ Code. Independent from the formatter we are using (K&R, BSD/Allman, GNU, Whitesmiths or a self defined one) we always get a if (!this->isOpenRead) return false; (the return directly under the if) while it should be if (!this->isOpenRead) return false; (the return with a tab or white spaces in front) When working with {} it's working fine. Do you know how we could solve this issue? Thanks a lot for your help and best regards, Andrea
I cannot reproduce this issue. I tested the following code, with CDT 8.4: class Foo { bool isOpenRead; bool foo() { if (!this->isOpenRead) return false; return true; } }; All of the built-in formatters correctly indented the return statement after the 'if'.
Yes, with the example you wrote the formatter is working fine. I found now out that after calling a specific function (we have defined in a header file) the wrong behavior is shown. I will do some more tests and then write the example here.
Created attachment 246304 [details] needed header file for testing formatter
Here now the example where we have problems, it's related to a macro that is called. /* * formatter_test.cpp * * Created on: Aug 25, 2014 * Author: eedanch */ #include "test_header.h" namespace EricssonDsc { class Foo { bool isOpenRead; bool foo() { FuncTrace; if (!this->isOpenRead) return false; return true; } }; } If we remove the line with "FuncTrace" then the formatting is correct. /* * formatter_test.cpp * * Created on: Aug 25, 2014 * Author: eedanch */ #include "test_header.h" namespace EricssonDsc { class Foo { bool isOpenRead; bool foo() { if (!this->isOpenRead) return false; return true; } }; }
Thanks, I can reproduce the issue with this example.