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++/11145] New: Overloading math functions sometimes fails if not in std namespace


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

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

           Summary: Overloading math functions sometimes fails if not in std
                    namespace
           Product: gcc
           Version: 3.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: derrick@cco.caltech.edu
                CC: gcc-bugs@gcc.gnu.org
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu

I am using a user defined numeric type with the Blitz++ library, but I get an error when trying to 
use the sqrt function. If I put the definition of sqrt for the user defined type in namespace std, then 
it works. I dug into the Blitz code, and I'm pretty sure this is compiler problem and not some bug 
in Blitz. Attached is some test code that exercises the bug. Ummmm... I assume that after I hit 
"Commit" I'll have a chance to attach the preprocessor file somewhere? If not, where do I send it?

Anyway, here's the output from g++ -v when we don't define FIX
Reading specs from /newman/user2/derrick/gnu/gcc-3.3/lib/gcc-lib/i686-pc-linux-gnu/3.3/
specs
Configured with: ../gcc-3.3/configure --prefix=/newman/user2/derrick/gnu/gcc-3.3
Thread model: posix
gcc version 3.3
 /newman/user2/derrick/gnu/gcc-3.3/lib/gcc-lib/i686-pc-linux-gnu/3.3/cc1plus -
fpreprocessed gmpblitz.err.ii -quiet -dumpbase gmpblitz.err.ii -auxbase gmpblitz.err -version -o 
/tmp/ccklCyj0.s
GNU C++ version 3.3 (i686-pc-linux-gnu)
        compiled by GNU C version 3.3.
GGC heuristics: --param ggc-min-expand=64 --param ggc-min-heapsize=64298
/newman/user2/derrick/gnu/gcc-3.3/include/c++/3.3/blitz/funcs.h: In static 
   member function `static T_numtype1 
   blitz::Fn_sqrt<T_numtype1>::apply(T_numtype1) [with T_numtype1 = MyFloat]':
/newman/user2/derrick/gnu/gcc-3.3/include/c++/3.3/blitz/array/expr.h:569:   instantiated 
from `typename P_op::T_numtype blitz::_bz_ArrayExprUnaryOp<P_expr, P_op>::operator()(const 
blitz::TinyVector<int, N_rank>&) [with int N_rank = 1, P_expr = blitz::FastArrayIterator<MyFloat, 
1>, P_op = blitz::Fn_sqrt<MyFloat>]'
/newman/user2/derrick/gnu/gcc-3.3/include/c++/3.3/blitz/array/expr.h:190:   instantiated 
from `typename P_expr::T_numtype blitz::_bz_ArrayExpr<P_expr>::operator()(const 
blitz::TinyVector<int, N_rank>&) [with int N_rank = 1, P_expr = 
blitz::_bz_ArrayExprUnaryOp<blitz::FastArrayIterator<MyFloat, 1>, blitz::Fn_sqrt<MyFloat> >]'
/newman/user2/derrick/gnu/gcc-3.3/include/c++/3.3/blitz/array/eval.cc:713:   instantiated 
from `blitz::Array<T, N>& blitz::Array<T, N>::evaluateWithIndexTraversal1(T_expr, T_update) 
[with T_expr = 
blitz::_bz_ArrayExpr<blitz::_bz_ArrayExprUnaryOp<blitz::FastArrayIterator<MyFloat, 1>, 
blitz::Fn_sqrt<MyFloat> > >, T_update = blitz::_bz_update<MyFloat, MyFloat>, P_numtype = 
MyFloat, int N_rank = 1]'
/newman/user2/derrick/gnu/gcc-3.3/include/c++/3.3/blitz/array/eval.cc:214:   instantiated 
from `blitz::Array<T, N>& blitz::Array<T, N>::evaluate(T_expr, T_update) [with T_expr = 
blitz::_bz_ArrayExpr<blitz::_bz_ArrayExprUnaryOp<blitz::FastArrayIterator<MyFloat, 1>, 
blitz::Fn_sqrt<MyFloat> > >, T_update = blitz::_bz_update<MyFloat, MyFloat>, P_numtype = 
MyFloat, int N_rank = 1]'
/newman/user2/derrick/gnu/gcc-3.3/include/c++/3.3/blitz/array/ops.cc:73:   instantiated from 
`blitz::Array<T, N>& blitz::Array<T, N>::operator=(const blitz::ETBase<T_expr>&) [with T_expr = 
blitz::_bz_ArrayExpr<blitz::_bz_ArrayExprUnaryOp<blitz::FastArrayIterator<MyFloat, 1>, 
blitz::Fn_sqrt<MyFloat> > >, P_numtype = MyFloat, int N_rank = 1]'
gmpblitz.cc:19:   instantiated from here
/newman/user2/derrick/gnu/gcc-3.3/include/c++/3.3/blitz/funcs.h:118: error: no 
   matching function for call to `sqrt(MyFloat&)'
<internal>:118: error: candidates are: double std::sqrt(double)
/newman/user2/derrick/gnu/gcc-3.3/include/c++/3.3/cmath:546: error:             
       float std::sqrt(float)
/newman/user2/derrick/gnu/gcc-3.3/include/c++/3.3/cmath:550: error:             
       long double std::sqrt(long double)


#include <blitz/array.h>
struct MyFloat {
};

#ifdef FIX
namespace std {
#endif
MyFloat sqrt(MyFloat);
#ifdef FIX
}
#endif

using namespace std;

void f() {
  MyFloat y;
  y = sqrt(y);  // works!
  blitz::Array< MyFloat, 1 > x;
  x = sqrt(x);  // doesn't work
}


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