Re: Renaming var causes curly bracket to be inserted

Simon Walter <simon-zltWpXmlfYsH0/[email protected]> Fri, 29 May 2020 03:40:35 +0900
Newsgroups gmane.comp.kde.users.kdevelop
Message-ID <[email protected]>
On 5/27/20 4:39 PM, Milian Wolff wrote:
> On Freitag, 22. Mai 2020 04:24:34 CEST Simon Walter wrote:
>> Hi all,
>>
>> First time posting to this list.
>>
>> static void kdevelop_var_rename_bug(void)
>> {
>>     //It doesn't have this problem on my laptop which has the exact
>>     //same version and exact same OS version.
>>     char * * Row = NULL; //right click on "Row" and choose "Rename..."
>>     if (false) abort(); //an extra curly brace will appear on the next line
>>     Row = NULL;
>>
>>     //It only happens when Row is right after an if that is not
>> contained in one
>>     //line
>>     if (false)
>>     {abort();}
>>     Row = NULL;
>>
>>     if (false) {abort();}//This causes the bug too.
>>     Row = NULL;
>>
>>     //Not if there no comment on the same line though!
>>     if (false) {abort();}
>>     Row = NULL;
>>
>>     //This triggers the problem too.
>>     if (false) abort();
>>     Row = NULL;
>> }
>>
>> In the above comment I mention another computer with the same version
>> that does not have this problem. The version is 5.0.3. I have downloaded
>> the 5.5.1 Appimage and tried that, and it still has this odd and painful
>> behavior.
>>
>> ...
> What code formatter do you have configured? Do you have astyle/uncrustify/
> clang-format or something like that?
>
> Otherwise can you create a standalone file (the above probably is missing some 
> header includes), such that we can investigate that on our side too?
>
> Thanks
>
Hello Mr. Wolff,

My apologize for the late reply.

I wasn't aware there was an external formatter involved for renaming. I
found the formatter location in the settings dialog, and it's on
Artistic Style. I don't have astyle installed - nor indent, but I did on
my laptop. So I removed them and a similar behavior occurred. Does that
it make it a clang bug? uncrustify looks interesting. I will try the
Custom Script Formatter. If I understand correctly, kdev_format_source
allows me to have per project formatting? Where do I place the
format_sources file?

Thank you for your help.

Attached is a c program that triggers this behavior.

If it's not reproducible on your side, is there any way I can help with
some debugging info?

Best regards,

Simon
var_rename.c (text/x-csrc, 1.8 KB)
#include <stdbool.h>
#include <stddef.h>

int main(int ArgCount, char * Arg[])
{
    //Right click on the var "renameMe" and choose: rename main::renameMe
    bool renameMe = false;
    if (renameMe) abort();
    
    
    
    
    
    
    
    
    renameMe = false;//A '}' will appear on this line.
    
    //This is fine
    if (renameMe)
    {abort();}
    renameMe = false;
    
    if (renameMe) {abort();}//This is not.
renameMe = false;//There needn't be any white space before.

    //But not if there no comment on the same line.
    if (renameMe) {abort();}
    
    
    
renameMe = false;

    renameMe = false;renameMe = false;renameMe = false;
    
    //The does seem like a formatter at work, but astyle is not installed.
    return 0;
}

//Here is the resulting text after using Rename: 
//==============================================================================
//
// #include <stdbool.h>
// #include <stddef.h>
// 
// int main(int ArgCount, char * Arg[])
// {
//     //Right click on the var "renameMe" and choose: rename main::renameMe
//     bool snth = false;
//     if ( snth ) abort();
//     
//     
//     
//     
//     
//     
//     
//     
//     }
// 
// 
// 
// 
// 
// 
// 
// 
//     snth = false;//A '}' will appear on this line.
//     
//     //This is fine
//     if ( snth )
//     {abort();}
//     snth = false;
//     
//     if ( snth ) {abort();}//This is not.
//     }
//     snth = false;//There needn't be any white space before.
// 
//     //But not if there no comment on the same line.
//     if ( snth ) {abort();}
//     
//     
//     
//     snth = false;
// 
//     snth = false;
//     snth = false;
//     snth = false;
//     
//     //The does seem like a formatter at work, but astyle is not installed.
//     return 0;
// }
//==============================================================================
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCAAdFiEEKjCfbP5oRo/LcFVTFXaa8r3aX0UFAl7QBagACgkQFXaa8r3a
X0WcYQ/8DgOlg699+oDSSS7Pi7VZhCCG2hw5ToQeCMEDSY5H4KgC/8eOoDbBUv4+
CbYALrd1gITOP0fNkfWQk5VKghoRb7oUItGaYP9pPjYM41bpeuTQGgNx0bZSbip2
wdWCywU0cReFZ7cbwPCco1k6AkcMSlzwCazZdKYyPQnD3eVUjgCX4t1Wf0m/X75u
QeJIE5RLv+WM6VRnUSM7wZO4cUlbTuTa7WMwl6d2hHq9SoOy9arYTsGgdHa6U1N8
jrgFFdtBTIO/ILhCQG+zgf1Ec7xAL7gHeMENtjxfj6rPUXRk15vmM52Y403tKVfE
zZpFSzLysX8HKhM3oIs3OUtcm2PbwV4HBKCnb7et5SWEbzFlvXhiHTxTU+4JtFPa
1ReeqhMzYxnjTqQZ3Fbw4kudygFutnSRZfHATx2mJn1fDaQ0jJFIFyvd1fh5PUDn
rLLfzU8O71Jsc7wEw7y3SdJgDe+Gd8plkbP18mfwaP1UrKoNh3UGwscaSwlxw9lP
QkeIt/wE+5tMJh32UQH+4ZBJ5pDsO0nCvIPIU89Q/dhmm/PQJFBShI5FY1zzH/sc
3H3SpuurIe2nEz+0wW6LfOj+dluoRydDOKjcC3uIqaCQijspNYwYZFYdDSzg6pSG
bmlKtAE4W/KnLvkJSaYpd6T/ABO6PGcislt2pvma7WHOHrNbo98=
=XqaH
-----END PGP SIGNATURE-----