This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/27791] New: assert() without -ansi doesnt print the failing condition


$ cat t.cc
#include <cassert>
int main()
{
  assert( false );
}

$ g++ -v
Using built-in specs.
Target: powerpc-ibm-aix5.2.0.0
Configured with: /tools/inst/jrichter/gcc-4.1.1/configure
--prefix=/tools/pkg/gcc/4.1.1 --enable-languages=c,c++ --disable-threads
--with-ld=/bin/ld --with-as=/bin/as
Thread model: aix
gcc version 4.1.1

$ g++ -o t t.cc
$ t
Assertion failed: __EX, file  t.cc, line 4
Resources lost(coredump)

$ g++ -ansi -o t t.cc
Assertion failed: false, file  t.cc, line 4
Resources lost(coredump)

Normally assert outputs the conditions that failed in the error message. But
not without -ansi. 


Here follows the relevant part of
lib/gcc/powerpc-ibm-aix5.2.0.0/4.1.1/include/assert.h
--------------------------------
#include <standards.h>

#if !defined(__NO_ASSERT_C99) && !defined(_NOISOC99_SOURCE)
#if __STDC_VERSION__ < 199901L && !defined(__C99__FUNC__)
#undef __ASSERT_C99   
#else
#if !defined(_ALL_SOURCE) && (!defined(_POSIX_C_SOURCE) || _POSIX_C_SOURCE >=
200112L)
#define __ASSERT_C99
#endif
#endif
#endif

#ifdef __ASSERT_C99

#if  defined(__STRICT_ANSI__)
#define assert(__EX) ((__EX) ? ((void)0) : __assert_c99(# __EX, __FILE__,
__LINE__, __func__))
#else
#define assert(__EX) ((__EX) ? ((void)0) : __assert_c99("__EX", __FILE__,
__LINE__, __func__))
#endif /* __STDC__*/

#else    /*  else if __ASSERT_C99 not defined */

#if  defined(__STRICT_ANSI__)
#define assert(__EX) ((__EX) ? ((void)0) : __assert(# __EX, __FILE__,
__LINE__))
#else
#define assert(__EX) ((__EX) ? ((void)0) : __assert("__EX", __FILE__,
__LINE__))
#endif /* __STDC__*/

#endif   /* __ASSERT_C99 */
#endif /* NDEBUG */
--------------------------------

You can see, depending on __STRICT_ANSI__ __EX is stringified or output as
string.  I think the macro expansion of __EX in string literals is pre-standard
and should not be used in a gcc header.


-- 
           Summary: assert() without -ansi doesnt print the failing
                    condition
           Product: gcc
           Version: 4.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: joerg dot richter at pdv-fs dot de
  GCC host triplet: powerpc-ibm-aix5.2.0.0


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27791


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]