handling C99 declarations after a case statement

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The kernel recently "moved to modern C99". https://lwn.net/Articles/885941/

We still have the -Wdeclaration-after-statement but one thing that we
can do now which trips up Sparse is declare variables immediately
after a case statement.

int x;
int test(void)
{
	switch (x) {
	case 4:
		int a;  <-- before you would have to add {} around this
		break;
	}
}

Sparse makes the "int a" into a STMT_EXPRESSION instead of a
STMT_DECLARATION and test-inspect doesn't like it:

$ ./test-inspect  test.c
test.c:7:17: error: typename in expression
test.c:7:21: error: Expected ; at end of statement
test.c:7:21: error: got a
test.c:7:17: error: undefined identifier 'int'

This causes a Smatch warning as well about a statement without any
effect.  The first code to trigger this was introduced in linux-next
yesterday.

regards,
dan carpenter



[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux