Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 353974 - Formatting C code does not work for certain uses of static_cast
Summary: Formatting C code does not work for certain uses of static_cast
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-editor (show other bugs)
Version: 8.0   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: 8.0.1   Edit
Assignee: Anton Leherbauer CLA
QA Contact: Anton Leherbauer CLA
URL:
Whiteboard:
Keywords:
: 356682 (view as bug list)
Depends on:
Blocks:
 
Reported: 2011-08-05 04:15 EDT by Ricardo Juan Palma urán CLA
Modified: 2011-09-06 05:17 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ricardo Juan Palma urán CLA 2011-08-05 04:15:36 EDT
Hi there.

I 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.
Comment 1 Anton Leherbauer CLA 2011-08-05 07:06:21 EDT
Fixed in master and 8.0.1.
Comment 2 CDT Genie CLA 2011-08-05 07:23:02 EDT
*** cdt git genie on behalf of Anton Leherbauer ***

    Bug 353974 - Formatting C code does not work for certain uses of static_cast

[*] http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=1f9bdc3019479026fd2ec641eda001e7072910fe
Comment 3 CDT Genie CLA 2011-08-05 07:23:03 EDT
*** cdt git genie on behalf of Anton Leherbauer ***

    Bug 353974 - Formatting C code does not work for certain uses of static_cast

[*] http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=35a5ad9dbbd9083cfa190fcdaff2a9c07ffa5358
Comment 4 Anton Leherbauer CLA 2011-09-06 05:17:30 EDT
*** Bug 356682 has been marked as a duplicate of this bug. ***