Bug 103017 - New glibc make assert() in C++ with pointer uncompilable.
New glibc make assert() in C++ with pointer uncompilable.
Status: CLOSED DUPLICATE of bug 102916
Product: Red Hat Raw Hide
Classification: Retired
Component: glibc (Show other bugs)
1.0
i386 Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
Brian Brock
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2003-08-25 11:14 EDT by John Eckerdal
Modified: 2016-11-24 10:12 EST (History)
2 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2006-02-21 13:58:13 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description John Eckerdal 2003-08-25 11:14:30 EDT
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 11:36:21 EDT

*** This bug has been marked as a duplicate of 102916 ***
Comment 2 D. Hugh Redelmeier 2004-07-10 15:57:50 EDT
perhaps this bug is related:
<https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=127606>
Comment 3 Red Hat Bugzilla 2006-02-21 13:58:13 EST
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.