Message ID | CA+8g5KG83STDuNKaUEhjYQAHNU5hm=+UdncBNn2hWRi0m2q6KQ@mail.gmail.com |
---|---|
State | New |
Headers | show |
On 12/15/2016 01:24 AM, Jim Meyering wrote: > Thanks. I didn't realize glibc used such a strict interpretation. > Happy to adjust. How's this (also in the attached, rebased commit): > > Let gcc detect assert(a = 1) errors. > * assert/assert.h (assert) Rewrite, retaining the old definintion > when required, but otherwise putting the expression as-is in an "if" > expression (hence, with no added parentheses) within a statement > expression. Thanks. I just noticed your fb.com address in the ChangeLog. Do you know if Facebook have filed paperwork with the FSF for glibc? Commit 7ee03f00188723a4de2b85021e511ced6d7fc4be was just two lines, and this commit here only adds only very few significant source lines, too, so we might get away without the paperwork, but this is probably the last such change we can accept. Anyway, please install if you have commit access. Thanks, Florian
On Fri, Dec 16, 2016 at 4:15 AM, Florian Weimer <fweimer@redhat.com> wrote: > On 12/15/2016 01:24 AM, Jim Meyering wrote: > >> Thanks. I didn't realize glibc used such a strict interpretation. >> Happy to adjust. How's this (also in the attached, rebased commit): >> >> Let gcc detect assert(a = 1) errors. >> * assert/assert.h (assert) Rewrite, retaining the old definintion >> when required, but otherwise putting the expression as-is in an >> "if" >> expression (hence, with no added parentheses) within a statement >> expression. > > > Thanks. I just noticed your fb.com address in the ChangeLog. Do you know > if Facebook have filed paperwork with the FSF for glibc? Commit > 7ee03f00188723a4de2b85021e511ced6d7fc4be was just two lines, and this commit > here only adds only very few significant source lines, too, so we might get > away without the paperwork, but this is probably the last such change we can > accept. > > Anyway, please install if you have commit access. Thanks. Pushed. I'll add glibc to my list for the next Facebook copyright assignment.
On Dez 14 2016, Jim Meyering <jim@meyering.net> wrote: > Thanks. I didn't realize glibc used such a strict interpretation. > Happy to adjust. How's this (also in the attached, rebased commit): > > Let gcc detect assert(a = 1) errors. > * assert/assert.h (assert) Rewrite, retaining the old definintion Missing colon. Andreas.
On 12/27/2016 06:47 PM, Andreas Schwab wrote: > On Dez 14 2016, Jim Meyering <jim@meyering.net> wrote: > >> Thanks. I didn't realize glibc used such a strict interpretation. >> Happy to adjust. How's this (also in the attached, rebased commit): >> >> Let gcc detect assert(a = 1) errors. >> * assert/assert.h (assert) Rewrite, retaining the old definintion > > Missing colon. I fixed this along with a couple of other ChangeLog typos. Thanks, Florian
diff --git a/ChangeLog b/ChangeLog index c08b711..0779419 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2016-11-25 Jim Meyering <meyering@fb.com> + + Let gcc detect assert(a = 1) errors. + * assert/assert.h (assert) Rewrite, retaining the old definintion + when required, but otherwise putting the expression as-is in an "if" + expression (hence, with no added parentheses) within a statement + expression. + 2016-12-14 Joseph Myers <joseph@codesourcery.com> [BZ #20947] diff --git a/assert/assert.h b/assert/assert.h index 729edeb..0f25131 100644 --- a/assert/assert.h +++ b/assert/assert.h @@ -82,10 +82,23 @@ extern void __assert (const char *__assertion, const char *__file, int __line) __END_DECLS -# define assert(expr) \ - ((expr) \ - ? __ASSERT_VOID_CAST (0) \ - : __assert_fail (#expr, __FILE__, __LINE__, __ASSERT_FUNCTION)) +/* When possible, define assert so that it does not add extra + parentheses around EXPR. Otherwise, those added parentheses would + suppress warnings we'd expect to be detected by gcc's -Wparentheses. */ +# if !defined __GNUC__ || defined __STRICT_ANSI__ +# define assert(expr) \ + ((expr) \ + ? __ASSERT_VOID_CAST (0) \ + : __assert_fail (#expr, __FILE__, __LINE__, __ASSERT_FUNCTION)) +# else +# define assert(expr) \ + ({ \ + if (expr) \ + ; /* empty */ \ + else \ + __assert_fail (#expr, __FILE__, __LINE__, __ASSERT_FUNCTION); \ + }) +# endif # ifdef __USE_GNU # define assert_perror(errnum) \