This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Fix tgmath.h for GCC 4.5
- From: "Joseph S. Myers" <joseph at codesourcery dot com>
- To: libc-alpha at sourceware dot org
- Date: Fri, 24 Oct 2008 21:28:06 +0000 (UTC)
- Subject: Fix tgmath.h for GCC 4.5
GCC 4.5 will implement the correct ISO C rules as to what counts as an
integer constant expression
<http://gcc.gnu.org/ml/gcc-patches/2008-10/msg01061.html>. glibc's
<tgmath.h> relies on the __floating_type macro expanding to something
the compiler considers an integer constant expression, and with my
patch the compiler now detects that the expansion of the
__floating_type definition I originally gave in
<http://sourceware.org/ml/libc-alpha/2000-07/msg00288.html> is not an
integer constant expression when "type" names a floating-point type
(casts to floating-point types are not permitted in integer constant
expressions). Thus <tgmath.h> needs fixing to work with newer
compilers. GCC 3.1 (which post-dates my original definition) and
later will fold calls to __builtin_classify_type (already used
elsewhere in <tgmath.h>) and accept the result in integer constant
expressions; this patch duly makes __floating_type use
__builtin_classify_type for GCC 3.1 and later.
2008-10-24 Joseph Myers <joseph@codesourcery.com>
* math/tgmath.h (__floating_type): Use __builtin_classify_type in
definition for GCC 3.1 and later.
Index: math/tgmath.h
===================================================================
RCS file: /cvs/glibc/libc/math/tgmath.h,v
retrieving revision 1.26
diff -u -r1.26 tgmath.h
--- math/tgmath.h 12 Jul 2007 18:09:46 -0000 1.26
+++ math/tgmath.h 24 Oct 2008 20:42:50 -0000
@@ -48,7 +48,12 @@
/* 1 if 'type' is a floating type, 0 if 'type' is an integer type.
Allows for _Bool. Expands to an integer constant expression. */
-# define __floating_type(type) (((type) 0.25) && ((type) 0.25 - 1))
+# if __GNUC_PREREQ (3, 1)
+# define __floating_type(type) (__builtin_classify_type ((type) 0) == 8 \
+ || __builtin_classify_type ((type) 0) == 9)
+# else
+# define __floating_type(type) (((type) 0.25) && ((type) 0.25 - 1))
+# endif
/* The tgmath real type for T, where E is 0 if T is an integer type and
1 for a floating type. */
--
Joseph S. Myers
joseph@codesourcery.com