https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89526

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
                 CC|                            |msebor at gcc dot gnu.org
         Resolution|---                         |WONTFIX

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
When NDEBUG is not defined GCC will certainly detect errors in assert
expressions.  But it's clear from the test case you meant warnings.  I'm not
sure I see what warning GCC could issue for assert("nullptr") or what it could
do to even help here.  The assert macro is implemented in the C library, so GCC
has little control over what it expands to.  Whatever it does expand to, GCC
does the same checking as in other code.  So for instance:

  $ cat t.c && gcc -O2 -S -Wall -Wextra t.c
  #include <assert.h>

  void f (unsigned i)
  {
    assert (i >= 0);
  }
  In file included from t.c:1:
  t.c: In function ‘f’:
  t.c:5:13: warning: comparison of unsigned expression >= 0 is always true
[-Wtype-limits]
      5 |   assert (i >= 0);
        |             ^~
  t.c:5:13: warning: comparison of unsigned expression >= 0 is always true
[-Wtype-limits]
      5 |   assert (i >= 0);
        |             ^~

Note the warning is duplicated because in Glibc's definition of assert the
expression appears twice.  That's on purpose but it has the unfortunate effect
when the warning isn't controlled by -Wpedantic.

/* The first occurrence of EXPR is not evaluated due to the sizeof,
   but will trigger any pedantic warnings masked by the __extension__
   for the second occurrence.  The ternary operator is required to
   support function pointers and bit fields in this context, and to
   suppress the evaluation of variable length arrays.  */
#  define assert(expr)                                                  \
  ((void) sizeof ((expr) ? 1 : 0), __extension__ ({                     \
      if (expr)                                                         \
        ; /* empty */                                                   \
      else                                                              \
        __assert_fail (#expr, __FILE__, __LINE__, __ASSERT_FUNCTION);   \
    }))


With that I have to resolve this as won't fix.

Reply via email to