freebsd-dev/usr.bin/indent/tests/elsecomment.0
Piotr Pawel Stefaniak ec5ac89ecd indent(1): improve handling of comments and newlines between "if (...)" or
"while (...)" and "else" or "{"

* Don't flush newlines - there can be multiple of them and they can happen
before a token that isn't else or {. Instead, always store them in save_com.
* Don't dump the buffer's contents on newline assuming that there is only
one comment before else or {.
* Avoid producing surplus newlines, especially before else when -ce is on.
* When -bl is on, don't treat { as a comment (was implemented by falling
through "case lbrace:" to "case comment:").

This commit fixes the above, but exposes another bug and thus breaks several
other tests. Another commit will make them pass again.
2018-06-03 14:03:20 +00:00

43 lines
555 B
Plaintext

/* $FreeBSD$ */
/* See r303484 and r309342 */
void t(void) {
/* The two if statements below excercise two different code paths. */
if (1) /* a */ int a; else /* b */ int b;
if (1) /* a */
int a;
else /* b */
int b;
if (1) {
}
/* Old indent would remove the 3 blank lines above, awaiting "else". */
if (1) {
int a;
}
else if (0) {
int b;
}
/* test */
else
;
if (1)
;
else /* Old indent would get very confused here */
/* We also mustn't assume that there's only one comment */
/* before the left brace. */
{
}
}