Take the following example: void f(int *a) { *a++ = __extension__ ({ int bb = *a; bb; }); } --- We don't warn for the operation on a. This is most likely we don't look into a BLOCK or a statement list, I don't know which one. If I remove the declation of bb, it works, so I am going to assume we don't look into BLOCKs. This was reduced from the following code with glibc and -O1: #include <ctype.h> void strtolower(char *data) { while (*data != '\0') *data++ = tolower(*data); }
Subject: Re: New: Missing "operation on xxx may be undefined" on obvious undefined code On Thu, 22 Sep 2005, pinskia at gcc dot gnu dot org wrote: > Take the following example: > void f(int *a) > { > *a++ = __extension__ ({ int bb = *a; bb; }); > } I'm not convinced this is undefined: statement expressions act like (inline) function calls for the purpose of sequence point rules so the execution of the statement expression suspends the execution of the rest of the surrounding expression and there are sequence points at the beginning and end of the statement expression. It is, however, at least unspecified order of evaluation and a warning here would still make sense.
(In reply to comment #1) > > It is, however, at least unspecified order of evaluation and a warning > here would still make sense. > A candidate for -Wsequence-points ?
It seems to me that __extension__ also inhibits some other useful warnings. For example: #include <string.h> int foo(void *x) { return strcmp(x + 1, "test"); } does not cause warnings when compiled with -Wpointer-arith -O1 (glibc v. 2.17). It can be reduced to: int foo(void *x) { return __extension__({ __builtin_strcmp(x + 1, "test"); }); } Note, that we do warn about int foo(void *x) { return ({ __builtin_strcmp(x + 1, "test"); }); }
Since arithmetic on void * (treating sizeof(void) as 1) is a GNU extension, that behavior is desirable.
(In reply to Manuel López-Ibáñez from comment #2) > (In reply to comment #1) > > > > It is, however, at least unspecified order of evaluation and a warning > > here would still make sense. > > > > A candidate for -Wsequence-points ? ...or a new flag?