add_ssaaaa and C++

Emmanuel Thomé Emmanuel.Thome at inria.fr
Sat May 21 19:58:29 CEST 2005


Here's a nasty bug with g++ and longlong.h ; not critical for gmp though.

currently, add_ssaaaa is defined on i386 (for example) as

#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
  __asm__ ("addl %5,%1\n\tadcl %3,%0"                                   \
           : "=r" ((USItype)(sh)), "=&r" ((USItype)(sl))                \
           : "0"  ((USItype)(ah)), "g" ((USItype)(bh)),                 \
             "%1" ((USItype)(al)), "g" ((USItype)(bl)))

Is there a reason for using the cast-to-lvalue extension ? Such
extensions are marked deprecated in gcc.

When including longlong.h from foreign code (which is somewhat calling
for problems, I agree), this macro causes problem with C++, since the
cast-to-lvalue does not exist in g++. The code does not compile:

x.c:36: error: ISO C++ forbids cast to non-reference type used as lvalue

More precisely, the feature has been disabled in favour of the
cast-to-reference feature, which would work as ((USItype&)(sh)). Such a
thing is invalid C++ however (and g++ silently produces bad code),
because sh might not be of type USItype (this feature is intended for
class hierarchies, not primitive types). This breaks even on i386 where
USItype and mp_limb_t have the same size, but are respectively typedef'ed
as uint and ulong (gasp).

In my local copy of longlong.h, I'm disabling the lvalue cast entirely in
C++, and might do so as well in C.

I am quite concerned by this bug, but I understand gmp may not be.
I leave it to you to decide whether this is worth fixing in gmp or not
(the proper fix may not be completely obvious).

E.


More information about the gmp-bugs mailing list