Hi Derek, On 2026-05-07T11:21:35-0400, Derek Martin wrote: > > Also please match the formatting style used in Mutt, i.e. Allman curly brace > > style, being free to omit the braces for single lines if you like. > > Due to past experience, I don't do this unless the conditional statement fits > comfortably on the same line as the conditional. It tends to lead to > bugs where someone expands what is done conditionally (or tries), but > they forget to add the braces, leading to a hard-to-see logic error.
This is not a real problem, and has not been a real problem for many
years (if not decades). -Wmisleading-indentation exists since GCC 6
(released in 2015), and is part of -Wall, and it precludes the
possibility of such logic errors.
alx@devuan:~/tmp$ cat braces.c
#include <stdio.h>
int
main(void)
{
if (1)
puts("foo");
puts("bar");
}
alx@devuan:~/tmp$ gcc -Wall braces.c
braces.c: In function ‘main’:
braces.c:6:9: warning: this ‘if’ clause does not guard...
[-Wmisleading-indentation]
6 | if (1)
| ^~
braces.c:8:17: note: ...this statement, but the latter is misleadingly
indented as if it were guarded by the ‘if’
8 | puts("bar");
| ^~~~
alx@devuan:~/tmp$ clang -Wall braces.c
braces.c:8:3: warning: misleading indentation; statement is not
part of the previous 'if' [-Wmisleading-indentation]
8 | puts("bar");
| ^
braces.c:6:2: note: previous statement is here
6 | if (1)
| ^
1 warning generated.
That is, the famous Apple bug[1] (discovered in 2012) was because these
compiler diagnostics weren't available yet. It's pretty much impossible
to repeat such a bug accidentally today. Tools have improved vastly.
You should optimize for readability, and leave safety to compilers.
[1]: <https://dwheeler.com/essays/apple-goto-fail.html>
Cheers,
Alex
--
<https://www.alejandro-colomar.es>
signature.asc
Description: PGP signature
