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]
Other format: [Raw text]

[Bug libstdc++/16862] New: can't compile self defined void distance(std::vector<T>, std::vector<T>)


The following program does not compile:

-----
#include <vector>
 
double distance(const std::vector<double> & v1, const std::vector<double> & v2) 
{
  return 0;
}
 
int main(int argc, char* argv[])
{
  std::vector<double> v;
  double d;
  d = distance(v, v);
  return 0;
}
----

In response to a post to gcc-bugs@gcc.gnu.org, Jim Wilson wrote:

----
I am not a C++ expert, so I am really not the right person to be looking at 
this.  However, I suspect the problem is that the vector 
class is itself defined in namespace std, and uses the iterator classes, and 
that is somehow causing the search for the distance 
function to also look at the interator classes.  It isn't just the name 
distance, any name in stl_interator.h seems to cause the 
same problem.
 
I can get your testcase to compile if I change
  d = distance(v, v);
to
  d = ::distance(v, v);
----
------- Additional Comment #3 From Wolfgang Bangerth 2004-06-10 14:45 [reply] -------
Jim is right -- the compiler looks into the namespace of the  
arguments when looking for a function 'distance' and therefore  
doesn't find the one in global namespace. It does find one  
in namespace std::, though, so tries to call it. In the  
process of this, it has to do some argument conversions, which  
fail -- this is what you get the error messages for.  
  
Jim already mentioned the correct way to write the program so  
that it compiles. Note that Intel's compiler also rejects this  
program.  
  
W.  

------- Additional Comment #13 From Paolo Carlini 2004-08-03 10:33 [reply] -------
I'm looking a bit into this. Frankly, I don't think we really want to complicate
std::distance with the enable_if bits. FWIW, Icc8 (+ Dinkum) behaves *exactly* in
the same way of gcc. On the other hand, the type traits support is in flux and
perhaps we'll be able to easily refine the library in these areas in the near
future. I'm suspending the PR.

-- 
           Summary: can't compile self defined void distance(std::vector<T>,
                    std::vector<T>)
           Product: gcc
           Version: 3.3.2
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P2
         Component: libstdc++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: pinskia at gcc dot gnu dot org
                CC: gcc-bugs at gcc dot gnu dot org,king dot benjamin at mh-
                    hannover dot de,pcarlini at suse dot de


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16862


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