closing braces not automatically inserted despite Preference setting (C++)

Did something change in Xcode 9 regarding the “automatically insert closing braces” preference? My checkbox for that option has been set for a long time. After I installed Xcode 9 (now at 9.0.1) the behavior changed in an unexpected way. If I am at “top level” — at the left margin, not inside a brace body — and I type an open brace:

void foo()
{<cursor_here>

then a return, I see:

void foo()
{
   <cursor_here>
}

which is what I expect. But if I am inside a brace body, I do not see the automatic insertion of the close brace:

void foo(bool b)
{
    if (b)
    {<cursor_here>
}

After a return I see:

void foo(bool b)
{
    if (b)
    {
        <cursor_here>
}

with no automatically inserted close brace. While trying this, I noticed that the close brace IS inserted if the open brace is not on its own line:

void foo(bool b)
{
    if (b) {<cursor_here>
}

After typing return:

void foo(bool b)
{
    if (b) {
        <cursor_here>
    }
}


Is there a way to get the pre-Xcode-9 behavior back?

Answered by cwr in 282819022

This appears to be fixed in Xcode 9.2
🙂

Happens in objc files also. I filed a bug report in Sept. about this (mis)behaviour occurring in Xcode 9 GM and the bug was closed as duplicate.

Thanks for letting me know. “Misery loves company.”

Accepted Answer

This appears to be fixed in Xcode 9.2
🙂

the same issue in xcode 10

It's started happening to me, too in Xcode 10, but I don't get a closing brace at any time and it happens only in one .cpp file in one project. Other files in the project are fine. I read another post that said the feature was disabled if the file included a block comment, but that hasn't affected other files. The file is over 1,100 lines, so maybe it's just the size of the file that's confused the editor? I suspect there's some anomaly in the way I've used braces somewhere that's not technically an error but the editor just doesn't want to keep track of it anymore.
closing braces not automatically inserted despite Preference setting (C++)
 
 
Q