Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 16 Apr 2004 15:28:40 -0400 (EDT)
From:      Jonathan Lennox <lennox@cs.columbia.edu>
To:        FreeBSD-gnats-submit@FreeBSD.org
Subject:   gnu/65641: Use of llabs() in C++ fails as ambiguous
Message-ID:  <200404161928.i3GJSeKD026740@cnr.cs.columbia.edu>
Resent-Message-ID: <200404161930.i3GJUQmK026866@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         65641
>Category:       gnu
>Synopsis:       Use of llabs() in C++ fails as ambiguous
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Apr 16 12:30:25 PDT 2004
>Closed-Date:
>Last-Modified:
>Originator:     Jonathan Lennox
>Release:        FreeBSD 5.2.1-RELEASE-p3 i386
>Organization:
Columbia University
>Environment:
System: FreeBSD cnr.cs.columbia.edu 5.2.1-RELEASE-p3 FreeBSD 5.2.1-RELEASE-p3 #4: Thu Mar 18 16:03:39 EST 2004 lennox@cnr.cs.columbia.edu:/usr/obj/usr/src/sys/CNR i386


	
>Description:

When I compile the program llabs.cxx (attached below) with the system g++ on
FreeBSD 5.2.1, it fails with:

llabs.cxx: In function `int main()':
llabs.cxx:9: error: call of overloaded `llabs(long long int&)' is ambiguous
/usr/include/stdlib.h:140: error: candidates are: long long int llabs(long long 
   int)
/usr/include/c++/3.3/cstdlib:152: error:                 long long int 
   __gnu_cxx::llabs(long long int)

This seems to be because it is picking up both ::llabs(long long) from
<stdlib.h> and __gnu_cxx::llabs(long long), imported into namespace std,
from <cstdlib>.

I don't know whether this is a problem with the baseline G++ or G++ as
imported into FreeBSD; if it's the former, please report this to the GCC
people (or I can).

>How-To-Repeat:

g++ llabs.cxx -o llabs

>Fix:

Unknown.

As a workaround, explicitly qualify the call to llabs as std::llabs().  Note
that this is not actually correct C++, though, since llabs is not defined by
the C++98 standard, and thus may not be portable.


--- llabs.cxx begins here ---
#include <cstdlib>

using namespace std;

int main()
{
  long long foo = -1LL, bar;

  bar = llabs(foo);

  return 0;
}
--- llabs.cxx ends here ---


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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200404161928.i3GJSeKD026740>