Bug 103017 - New glibc make assert() in C++ with pointer uncompilable.
Summary: New glibc make assert() in C++ with pointer uncompilable.
Status: CLOSED DUPLICATE of bug 102916
Alias: None
Product: Red Hat Raw Hide
Classification: Retired
Component: glibc
Version: 1.0
Hardware: i386
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: Brian Brock
URL:
Whiteboard:
Keywords:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2003-08-25 15:14 UTC by John Eckerdal
Modified: 2016-11-24 15:12 UTC (History)
2 users (show)

(edit)
Clone Of:
(edit)
Last Closed: 2006-02-21 18:58:13 UTC


Attachments (Terms of Use)

Description John Eckerdal 2003-08-25 15:14:30 UTC
From Bugzilla Helper:
User-Agent: Opera/7.20 (X11; Linux i686; U)  [en]

Description of problem:
The new glibc (or GCC, not sure) makes it impossible to compile programs which 
use assert when checking pointers. I first noticed this problem in ScummVM which 
uses C++ and then I tried to compile ClanLib (also C++) and the same problem is 
there also.

As far as I understand it is legit to assert() with pointers.

Example program:

#include <stdio.h>
#include <assert.h>

typedef unsigned char byte;

int main(void)
{
  int* nisse1 = NULL;
  byte* nisse2 = NULL;
  assert(nisse1);
  assert(nisse2);

  return 0;
}

Compile this with:

g++ -Wall -o test test.cc
test.cc: In function `int main()':
test.cc:10: error: invalid conversion from `int*' to `long int'
test.cc:11: error: invalid conversion from `byte*' to `long int'

Same program with gcc (not C++):

gcc -o test test.c
test.c: In function `main':
test.c:10: warning: passing arg 1 of `__builtin_expect' makes integer from 
pointer without a cast
test.c:11: warning: passing arg 1 of `__builtin_expect' makes integer from 
pointer without a cast

If I change the program to 

#include <stdio.h>
#include <assert.h>

typedef unsigned char byte;

int main(void)
{
  int* nisse1 = NULL;
  byte* nisse2 = NULL;
  assert(nisse1 != NULL);
  assert(nisse2 != NULL);

  return 0;
}

It works fine.

It seems like this problem is related to the addition of __builtin_expect in the 
assert.h file provided by glibc. This function takes a long in, and C++ will 
fail to cast a pointer to a long. C will produce a warning.


Version-Release number of selected component (if applicable):
glibc-2.3.2-71

How reproducible:
Always

Steps to Reproduce:
1. Enter the first testsnippet in an editor
2. Try to compile (g++ -o test test.cc)
3. See it fail to compile
    

Actual Results:  The programs did not compile

Expected Results:  That the programs should compile.

Additional info:

Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.3.1/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man 
--infodir=/usr/share/info --enable-shared --enable-threads=posix 
--disable-checking --with-system-zlib --enable-__cxa_atexit 
--host=i386-redhat-linux
Thread model: posix
gcc version 3.3.1 20030814 (Red Hat Linux 3.3.1-2)

Comment 1 Bill Nottingham 2003-08-25 15:36:21 UTC

*** This bug has been marked as a duplicate of 102916 ***

Comment 2 D. Hugh Redelmeier 2004-07-10 19:57:50 UTC
perhaps this bug is related:
<https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=127606>

Comment 3 Red Hat Bugzilla 2006-02-21 18:58:13 UTC
Changed to 'CLOSED' state since 'RESOLVED' has been deprecated.


Note You need to log in before you can comment on or make changes to this bug.