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 c++/11970] New: Problems with ADL


PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

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

           Summary: Problems with ADL
           Product: gcc
           Version: 3.4
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: poschmid at lbl dot gov
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu

The code t1.C is not accepted by gcc 3.4. g++ claims that the call to
transform is ambiguous. I believe the code is legal since the transform
function is qualified at the call site thus inhibiting ADL. Previous versions
of gcc accepted this code.

Environment:
System: Linux linux 2.4.20-4GB #1 Fri Jul 11 07:33:18 UTC 2003 i686 unknown unknown GNU/Linux
Architecture: i686
SuSE 8.2
glibc 2.3.2
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: ../gcc/configure --enable-threads=posix --enable-languages=c,c++,f77,objc --enable-__cxa_atexit --enable-debug

How-To-Repeat:
source code t1.c
namespace std
{
template <class _Arg, class _Result>
struct unary_function {
  typedef _Arg argument_type;   
  typedef _Result result_type;  
};
template <class _Arg1, class _Arg2, class _Result>
struct binary_function {
  typedef _Arg1 first_argument_type;   
  typedef _Arg2 second_argument_type;  
  typedef _Result result_type;         
};      

template <class _Operation> 
class binder1st
  : public unary_function<typename _Operation::second_argument_type,
                          typename _Operation::result_type> {
protected:
  _Operation op;
  typename _Operation::first_argument_type value;
public:
  binder1st(const _Operation& __x,
            const typename _Operation::first_argument_type& __y)
      : op(__x), value(__y) {}
  typename _Operation::result_type
  operator()(const typename _Operation::second_argument_type& __x) const {
    return op(value, __x); 
  }
};

template <class _Operation, class _Tp>
inline binder1st<_Operation> 
bind1st(const _Operation& __fn, const _Tp& __x) 
{
  typedef typename _Operation::first_argument_type _Arg1_type;
  return binder1st<_Operation>(__fn, _Arg1_type(__x));
}

template <class InputIterator, class OutputIterator, class UnaryOperation>
inline
OutputIterator
transform(InputIterator , InputIterator ,
          OutputIterator r, UnaryOperation)
{
  OutputIterator result = r;
  return result;
}

}
namespace mtl
{
template<class T, unsigned int thesize>
class carray {
  private:
    T v[thesize];  
  public:
    typedef T        value_type;
    typedef T*       iterator;
    typedef const T* const_iterator;
    iterator begin() { return v; }
    iterator end() { return v+thesize; }
};

}

namespace mtl_algo {
template <class InputIterator, class OutputIterator, class UnaryOperation>
inline
OutputIterator
transform(InputIterator , InputIterator ,
          OutputIterator r, UnaryOperation)
{
  OutputIterator result = r;
  return result;
}

}
namespace mtl {

template <class S, class T, class R>
struct mtl_multiplies : std::binary_function<S, T, R> {
  typedef S first_argument_type;
  typedef T second_argument_type;
  typedef R result_type;
  R operator () (const S& x, const T& y) const { return x * y; }
};

template <class Vector, class T> inline
void
scale(Vector& x, const T& alpha)
{
  typedef typename Vector::value_type VT;
  mtl_algo::transform(x.begin(), x.end(), x.begin(),
                      std::bind1st(mtl_multiplies<T,VT,VT>(), alpha));
}

} 

int main ()
{
  typedef mtl::carray<double,5> compVec;
  compVec c;
  mtl::scale(c,2.0);
}

g++ -v -W -Wall t1.C 
Reading specs from /usr/local/lib/gcc/i686-pc-linux-gnu/3.4/specs
Configured with: ../gcc/configure --enable-threads=posix --enable-languages=c,c++,f77,objc --enable-__cxa_atexit --enable-debug
Thread model: posix
gcc version 3.4 20030816 (experimental)
 /usr/local/libexec/gcc/i686-pc-linux-gnu/3.4/cc1plus -quiet -v -D_GNU_SOURCE t1.C -quiet -dumpbase t1.C -mtune=pentiumpro -auxbase t1 -W -Wall -version -o /tmp/ccKLIXhH.s
ignoring nonexistent directory "NONE/include"
ignoring nonexistent directory "/usr/local/lib/gcc/i686-pc-linux-gnu/3.4/../../../../i686-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/lib/gcc/i686-pc-linux-gnu/3.4/../../../../include/c++/3.4
 /usr/local/lib/gcc/i686-pc-linux-gnu/3.4/../../../../include/c++/3.4/i686-pc-linux-gnu
 /usr/local/lib/gcc/i686-pc-linux-gnu/3.4/../../../../include/c++/3.4/backward
 /usr/local/include
 /usr/local/lib/gcc/i686-pc-linux-gnu/3.4/include
 /usr/include
End of search list.
GNU C++ version 3.4 20030816 (experimental) (i686-pc-linux-gnu)
	compiled by GNU C version 3.4 20030816 (experimental).
GGC heuristics: --param ggc-min-expand=47 --param ggc-min-heapsize=31899
t1.C: In function `void mtl::scale(Vector&, const T&) [with Vector = 
   main()::compVec, T = double]':
t1.C:104:   instantiated from here
t1.C:94: error: call of overloaded `transform(double*, double*, double*, 
   std::binder1st<mtl::mtl_multiplies<double, double, double> >)' is ambiguous
t1.C:73: note: candidates are: OutputIterator 
   mtl_algo::transform(InputIterator, InputIterator, OutputIterator, 
   UnaryOperation) [with InputIterator = double*, OutputIterator = double*, 
   UnaryOperation = std::binder1st<mtl::mtl_multiplies<double, double, double> 
   >]
t1.C:45: note:                 OutputIterator std::transform(InputIterator, 
   InputIterator, OutputIterator, UnaryOperation) [with InputIterator = 
   double*, OutputIterator = double*, UnaryOperation = 
   std::binder1st<mtl::mtl_multiplies<double, double, double> >]


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