Use __SIZEOF_LONG__ and __SIZEOF_LONG_LONG__ to determine the type of
streamoff at compile time instead of _GLIBCXX_HAVE_INT64_T_LONG and
_GLIBCXX_HAVE_INT64_T_LONG_LONG.

Currently the type of streamoff is determined at libstdc++ configure
time, chosen by the definitions of _GLIBCXX_HAVE_INT64_T_LONG and
_GLIBCXX_HAVE_INT64_T_LONG_LONG.  For a multilib configuration, the
difference is encoded in the different multilib header file paths.
For "FAT" library targets that package 32 bit and 64 bit libraries
together, G++ also expects a single header file directory hierarchy,
causing an incorrect value for streamoff in some situations.

This patch changes the only use of _GLIBCXX_HAVE_INT64_T_XXX to test
__SIZEOF_LONG__ and __SIZEOF__LONG_LONG__ at compile time.  Because
libstdc++ explicitly probes the type of __int64_t to choose the
declaration of streamoff, this patch only performs the dynamic
determination if either _GLIBCXX_HAVE_INT64_T_LONG or
_GLIBCXX_HAVE_INT64_T_LONG_LONG are defined.  In other words, it does
assume that if either one is defined, the other is defined, i.e., that
__int64_t is a typedef for one of those two types when one or the
other is present.  But it then dynamically chooses the type based on
the size of "long" and "long long" instead of using the configure time
value so that the header dynamically adapts to the 32/64 mode of GCC.
If neither __GLIBCXX_HAVE_INT64_T_XXX macro is defined, the original
logic proceeds, using either __int64_t or "long long".

Based on the configure time definitions, the size should be one or the
other when one of the macros is defined.  I can add an error case if
neither __SIZEOF_LONG__ nor __SIZEOF_LONG_LONG__ are 8 despite
__GLIBCXX_HAVE_INT64_T_XXX defined.

Is this an acceptable solution to determine the value at compile-time?

Thanks, David

diff --git a/libstdc++-v3/include/bits/postypes.h
b/libstdc++-v3/include/bits/postypes.h
index cb44cfe1396..81b9c4c6ae5 100644
--- a/libstdc++-v3/include/bits/postypes.h
+++ b/libstdc++-v3/include/bits/postypes.h
@@ -84,10 +84,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
    *  Note: In versions of GCC up to and including GCC 3.3, streamoff
    *  was typedef long.
   */
-#ifdef _GLIBCXX_HAVE_INT64_T_LONG
+#if defined(_GLIBCXX_HAVE_INT64_T_LONG) \
+    || defined(_GLIBCXX_HAVE_INT64_T_LONG_LONG)
+
+#if __SIZEOF_LONG__ == 8
   typedef long          streamoff;
-#elif defined(_GLIBCXX_HAVE_INT64_T_LONG_LONG)
+#elif __SIZEOF_LONG_LONG__ == 8
   typedef long long     streamoff;
+#endif
+
 #elif defined(_GLIBCXX_HAVE_INT64_T)
   typedef int64_t       streamoff;
 #else

Reply via email to