comments moved to previous line when performing re-format

When I perform a re-format action where there are comments on the line(s) between lines of code, the first line of the comment is always moved to the end of the previous line of code. I've messed with line spacing, carriage return settings, and other settings, and can't seem to find a way to prevent this behavior. What am I doing wrong? Thanks in advance.

 

Example:

before:

```

else
                {
                    /* Neither are set. */ /* We cannot accept this.  */
                    newret = CONFNAK; /* Give the peer our idea of what can be used,
                       so it can choose and confirm */
                    pcb.ccp_hisoptions.mppe = pcb.ccp_allowoptions.mppe;
                } 
               
                /* rebuild the opts */
                mppe_opts_to_ci(pcb.ccp_hisoptions.mppe, pkt.data() + 2);
                if (newret == CONFACK)
                {

```

after:

```
else
                {
                    /* Neither are set. */ /* We cannot accept this.  */
                    newret = CONFNAK; /* Give the peer our idea of what can be used,
                       so it can choose and confirm */
                    pcb.ccp_hisoptions.mppe = pcb.ccp_allowoptions.mppe;
                } /* rebuild the opts */
                mppe_opts_to_ci(pcb.ccp_hisoptions.mppe, pkt.data() + 2);
                if (newret == CONFACK)
                {

```

 

4 comments
Comment actions Permalink

Hello,

This is probably a bug. Could you please create a standalone snippet of code which reproduces the issue? I don't get the same behavior on 2019.2 if I reformat the following code:

void foo(int t)
{
    if (t) {}
    else
    {
        /* Neither are set. */ /* We cannot accept this. */
        t = 1; /* Give the peer our idea of what can be used,
          so it can choose and confirm */
        t = 2;
    }

    /* rebuild the opts */
    t = 3;
}
0
Comment actions Permalink

To provide further information, I've discovered if I set "C++"->"Formatting Style"->"Spaces"->"Other"->"Preserve space before end of line comment" to true, then this problem does not occur. Otherwise any block of code with comments will cause this issue for me.

 

With that option set to false, this snippet re-produces the issue for me:

```

void
ccp_set(PppPcb* pcb,
        uint8_t isopen,
        uint8_t isup,
        uint8_t receive_method,
        uint8_t transmit_method)
{
    pcb->ccp_receive_method = receive_method;
    // comment here
    pcb->ccp_transmit_method = transmit_method; 
 
} 

```

 

 

0
Comment actions Permalink

Thanks a lot, we can reproduce the problem. This issue will be tracked in https://youtrack.jetbrains.com/issue/RSCPP-27513. Please keep "Preserve space before end of line comment" set to true as a workaround for now.

0
Comment actions Permalink

thanks for your help I appreciate it.

0

Please sign in to leave a comment.