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

Bug#123468: c/6906: warn about asserts with side effects



Synopsis: warn about asserts with side effects

State-Changed-From-To: open->feedback
State-Changed-By: bangerth
State-Changed-When: Tue Jan  7 17:40:58 2003
State-Changed-Why:
    As much as I sympathize with the goal of such a warning, I
    doubt it will be possible to implement it. The reason is
    that assert() is usually implemented via a macro. On my
    system, it reads (if !NDEBUG):
    --------------------
    # define assert(expr) \
      (__ASSERT_VOID_CAST ((expr) ? 0 :                                           \
                           (__assert_fail (__STRING(expr), __FILE__, __LINE__,    \
                                           __ASSERT_FUNCTION), 0)))
    ---------------------------
    so at the time the _compiler_ (as opposed to the
    preprocessor) sees the condition, the special name "assert"
    is already gone. On the other hand, the preprocessor doesn't
    know anything about expressions with or without side effects.
    
    I thus seriously doubt that such a warning can be implemented
    without gross hacks...
    
    W.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=6906



Reply to: