Going mad over Xcode 12 indentation issue of "for"

Specifically, it seems to affect regular for loops (not the new “ranged” ones).
After I have typed the line with the for and hit “return” to go to the new line below it, it does this

for (int i = 0; i < 10; ++i)
| //< caret ends there when I hit return

Xcode 12 seems to believe that the following line should be at the same level of the for.

The problem is not just while typing, because with the option to reformat the code when copy/pasting, it messes up the indentation if there are such one-line fors in the pasted code.

And also, even if you type the extra “tab” key to indent the line correctly while you’re at it, then when you type the semicolon at the end of the line, it gets auto-indented (incorrectly) at the same level of the for.

Xcode 12 users, can you confirm it’s behaving like that for you too, or is it mine that possibly has configuration issues?

(Xcode 11, which I still have, behaves as expected though)

Same here, drives me crazy!

I haven’t experienced this yet not having moved to Xcode 12. But for the copy-paste case, maybe Paste and Preserve Formatting option is a workaround for now?

I had something similar happening to me, but it sort of magically fixed itself (there’s a possibility I fiddled with the settings, but I’ve no idea what I specifically did to make it work).

My settings look like this:


I have to say that Xcode seems like the worst editor I’ve ever used. VS Code seems to have really good support for C++ these days - is anyone using it? Would I still need to use Xcode to build for iOS or does a make handle that now?

I have set your same settings but the line after the for still refuses to intent properly.

I’ve noticed it happens as soon as there’s a semicolon inside the for parentheses, which obviously is mandated by its syntax but at least I’ve been able to understand why the “ranged” for doesn’t have the issue

Strange, I’ve no idea then why it started working for me, perhaps a stray cosmic ray flipped a bit and the planets aligned correctly for it to magically start behaving. It annoyed the hell out of me before, so I feel your pain.