SOLVED? C++ paren auto-complete bug

Report issues, odd behaviors or submit a detailed bug report.
Post Reply
User avatar
DerellLicht1
Posts: 175
Joined: 23 Jul 2021 17:38
Location: Fremont, CA, USA

SOLVED? C++ paren auto-complete bug

Post by DerellLicht1 »

I have experienced this quirk before, but until now it hasn't been a big issue...
Here is an example of the bug:

I start with this string:

Code: Select all

build_dir_tree (target[l]) ;
I need to insert the following after the closing square bracket:

Code: Select all

.c_str()
When I type in the opening paren, the editor auto-inserts the closing paren as well - but it also *deletes* the closing paren that was already there, so I get this:

Code: Select all

build_dir_tree (target[l].c_str() ;
Notice that one of the closing parens is missing...
This is *really* getting to be a headache at the moment, as I'm going back through my old c++ programs and converting my old string handling functions to use wstring classes...
So I am adding a *lot* of

Code: Select all

.c_str()
to existing code !! I end up repeatedly having to deal with compile errors because I didn't notice that this happened while I was typing...

Is there anything that I can do, to eliminate that paren deletion (other than completely disabling paren completion) ??
User avatar
DerellLicht1
Posts: 175
Joined: 23 Jul 2021 17:38
Location: Fremont, CA, USA

Re: C++ paren auto-complete bug

Post by DerellLicht1 »

BTW, the same thing happens in this case:

Code: Select all

syslog("");
for tchar translation, I have to place _T() around the existing quote pair...
So I type _T( in front of the first quote, but as soon as I type the opening paren, the closing paren is auto-inserted after the second quote - but it deletes the closing paren that was already there, leaving:

Code: Select all

syslog(_T("");
User avatar
Rickard Johansson
Site Admin
Posts: 6807
Joined: 19 Jul 2006 14:29

Re: C++ paren auto-complete bug

Post by Rickard Johansson »

Actually, in the cases above the editor does not insert a closing parentheses.

1. When you add .c_str() in build_dir_tree (target[l]) ; you get

Code: Select all

build_dir_tree (target[l].c_str(|) ;
the text caret | is to the right of the opening parentheses. The ")" is the old one and not inserted by the editor.
When you press ")" the text caret jumps over closing ")". This is by design. To add another ")" just press ")" again.

Same thing happens in the second example. No closing ")" is added. You have to add one yourself.

Note that almost every editor works differently with the same code...
User avatar
DerellLicht1
Posts: 175
Joined: 23 Jul 2021 17:38
Location: Fremont, CA, USA

Re: C++ paren auto-complete bug

Post by DerellLicht1 »

Well, no, that is not what happens...

Let's take this example; I just typed it in my program, just now:

I have this line:

Code: Select all

_tcscat (dirpath, cur_node->name);
I need to add

Code: Select all

.c_str()
after name. So I type

Code: Select all

.c_str(
, and I see this:

Code: Select all

_tcscat (dirpath, cur_node->name.c_str();
NOTE: I did not yet the closing paren, what is there, is the one that was already present.
I then type the closing paren, and get this:

Code: Select all

_tcscat (dirpath, cur_node->name.c_str();
NOTE that I should have had two closing parents at this point: the one that was already there, and the one that I just typed.
BUT THAT IS NOT WHAT HAPPENS!!!!!!!!!!!!!!!!!!!
Instead, the closing paren that I type, *over-writes* the closing paren that was already there!!!
So I end up having to always type *TWO* closing parens ...

That is the bug that I am reporting... and it *is* there.
User avatar
Rickard Johansson
Site Admin
Posts: 6807
Joined: 19 Jul 2006 14:29

Re: C++ paren auto-complete bug

Post by Rickard Johansson »

I realize you may not have tried as many editors as I have, but it's not a bug. It's just a different behavior from what you are used to. Almost every editor handles this differently. VS Code does one thing, Sublime Text another, NotePad++ yet another way (which is almost the same as in TextEd), etc.

NotePad++ will overwrite the ), just as RJ TextEd, but it inserts a closing ) after. So you don't have to add it yourself.

Some editors simple add () regardless of the code around the text caret.
So if you have syslog("") and you type _T( you end up with syslog(_T()"").

There is no standard way to handle auto parentheses completion. So editors have different behavior. It's not a bug.
User avatar
Rickard Johansson
Site Admin
Posts: 6807
Joined: 19 Jul 2006 14:29

Re: C++ paren auto-complete bug

Post by Rickard Johansson »

I've made a small change in the next release so you don't have to press ) twice.

BTW. You can disable the auto closure of braces in options.
User avatar
DerellLicht1
Posts: 175
Joined: 23 Jul 2021 17:38
Location: Fremont, CA, USA

Re: C++ paren auto-complete bug

Post by DerellLicht1 »

Rickard Johansson wrote: 29 Jun 2025 17:12 I've made a small change in the next release so you don't have to press ) twice.

BTW. You can disable the auto closure of braces in options.
Thank you so much!!!
Post Reply