Bug 571886 - Internal formatter goes wild with modern C++
Summary: Internal formatter goes wild with modern C++
Status: NEW
Alias: None
Product: CDT
Classification: Tools
Component: cdt-editor (show other bugs)
Version: 10.1.0   Edit
Hardware: PC Windows 10
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact: Jonah Graham CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-03-11 10:09 EST by mo st CLA
Modified: 2021-03-14 10:19 EDT (History)
2 users (show)

See Also:


Attachments
My custom format file. (21.57 KB, text/xml)
2021-03-11 10:09 EST, mo st CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description mo st CLA 2021-03-11 10:09:34 EST
Created attachment 285803 [details]
My custom format file.

Hello,

the internal formatter can't handle some constructs related to references. The following code:

     #include <unordered_map>

     std::unordered_map<int, long> mymap;

     long inc(int i) {
         mymap.at(i)++;
         return mymap.at(i);
     }

gets formatted to

     #include <unordered_map>

     std::unordered_map<int, long> mymap;

     long inc(int i) {
         mymap.at(i)++;return
     mymap    .at(i);
     }

I have this with many references and i don't know whats happening. But this bug sometimes affects only the following statement and sometimes some more of the following lines. Also, the on-/off-tags don't work properly:

     #include <unordered_map>

     std::unordered_map<int, long> mymap;

     namespace bug::lol {
         void something();
     }

     long inc(int i) {
        mymap.at(i)++;
        // @formatter:off
        return mymap.at(i);
        // @formatter:on
     }
     void bug::lol::something() {

     }

*sometimes* gets to

     #include <unordered_map>

     std::unordered_map<int, long> mymap;

     namespace bug::lol {
         void something();
     }

     long inc(int i) {
         mymap.at(i)++;
         // @formatter:off
         return mymap.at(i);
             // @formatter:on
     }void bug::lol::something() {

     }

Notice the intendation of the @formatter:on tag and the missing new line before the void bug::lol::something() (even before the formatter run). I can't reproduce the second example every single time. Sometimes the formatter removes new lines, sometimes it adds spaces. But every time it goes wild and trahes my code.

I've attached my custom format file.

Regards :)
Comment 1 mo st CLA 2021-03-14 10:19:24 EDT
I think the problem is much worse than i expected. For example i get the following formatting results:

     ...
     virtual void drawImage(const Drawing::Image &image,
                                    const Drawing::Rectangle &destination,
                                    double rotation =
                     0.0,
                                    const Drawing::FlipMode &flip = Drawing::FlipMode::NONE) const
                                            override;

     virtual void void drawImage(const Drawing::Image &image,
                     const Drawing::Rectangle &clip,
                     decltype(Drawing::Point::x) x,
                     decltype(Drawing::Point::y) y,
                                         double rotation = 0.0,
                                         const Drawing::FlipMode &flip = Drawing::FlipMode::NONE) const
                                                 override;
     ...

It also seems that the formatter really don't like decltypes.