This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

libstdc++/2190: abs(long), div(long,long) defined in <cmath> instead of <cstdlib>



>Number:         2190
>Category:       libstdc++
>Synopsis:       abs(long), div(long,long) defined in <cmath> instead of <cstdlib>
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          rejects-legal
>Submitter-Id:   net
>Arrival-Date:   Mon Mar 05 14:06:05 PST 2001
>Closed-Date:
>Last-Modified:
>Originator:     scott snyder
>Release:        3.0 20010305 (prerelease)
>Organization:
>Environment:
System: Linux karma 2.2.16-22 #1 Tue Aug 22 16:49:06 EDT 2000 i686 unknown
Architecture: i686

	
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: ../egcs/configure --prefix=/usr/local/egcs --enable-threads=posix --enable-long-long
>Description:

libstdc++ defines the long versions of abs and div in cmath, rather
than in cstdlib, as clause 26.5 of the standard seems to require.
This causes the program below to be rejected with ambiguity
errors if the compiler is configured with --enable-long-long.

>How-To-Repeat:

Configure the compiler with --enable-long-long.
Then, compiling this source

--------------------------------------------
#include <cstdlib>

int  main()
{
  long a = std::abs (1L);
  ldiv_t b = std::div (2L, 1L);
}
--------------------------------------------

gives the errors

$ g++ -c x.cc
x.cc: In function `int main()':
x.cc:5: call of overloaded `abs(long int)' is ambiguous
/usr/local/egcs/include/g++-v3/bits/std_cstdlib.h:123: candidates are: int 
   std::abs(int)
/usr/local/egcs/include/g++-v3/bits/std_cstdlib.h:135:                 long 
   long int std::abs(long long int)
x.cc:6: call of overloaded `div(long int, long int)' is ambiguous
/usr/local/egcs/include/g++-v3/bits/std_cstdlib.h:125: candidates are: div_t 
   std::div(int, int)
/usr/local/egcs/include/g++-v3/bits/std_cstdlib.h:142:                 lldiv_t 
   std::div(long long int, long long int)


>Fix:


2001-03-05  scott snyder  <snyder@fnal.gov>

	* include/c_std/bits/std_cmath.h: Move abs(long), div(long,long)
	from here...
	* include/c_std/bits/std_cstdlib.h: ... to here.


Index: include/c_std/bits/std_cmath.h
===================================================================
RCS file: /cvs/gcc/egcs/libstdc++-v3/include/c_std/bits/std_cmath.h,v
retrieving revision 1.6
diff -u -p -c -r1.6 std_cmath.h
*** std_cmath.h	2001/02/05 22:27:40	1.6
--- std_cmath.h	2001/03/05 21:48:41
*************** namespace std 
*** 80,91 ****
        return __x < _Tp() ? -__x : __x;
      }
  
-   inline long 
-   abs(long __i) { return ::labs(__i); }
- 
-   inline ldiv_t
-   div(long __i, long __j) { return ::ldiv(__i, __j); }
- 
  #if _GLIBCPP_HAVE___BUILTIN_FABSF
    inline float 
    abs(float __x) { return __builtin_fabsf(__x); }
--- 80,85 ----
Index: include/c_std/bits/std_cstdlib.h
===================================================================
RCS file: /cvs/gcc/egcs/libstdc++-v3/include/c_std/bits/std_cstdlib.h,v
retrieving revision 1.7
diff -u -p -c -r1.7 std_cstdlib.h
*** std_cstdlib.h	2001/02/05 22:27:40	1.7
--- std_cstdlib.h	2001/03/05 21:48:41
*************** namespace std 
*** 130,135 ****
--- 130,141 ----
    extern "C" size_t mbstowcs(wchar_t*, const char*, size_t); 
    extern "C" size_t wcstombs(char*, const wchar_t*, size_t);
  
+   inline long 
+   abs(long __i) { return ::labs(__i); }
+ 
+   inline ldiv_t
+   div(long __i, long __j) { return ::ldiv(__i, __j); }
+ 
  #ifdef _GLIBCPP_USE_LONG_LONG
    inline long long 
    abs(long long __x) { return __x >= 0 ? __x : -__x; }

>Release-Note:
>Audit-Trail:
>Unformatted:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]