blitzpp / blitz

Blitz++ Multi-Dimensional Array Library for C++
https://github.com/blitzpp/blitz/wiki
Other
405 stars 84 forks source link

a safeToReturn() issue #59

Open slayoo opened 5 years ago

slayoo commented 5 years ago

Migrated from: https://sourceforge.net/p/blitz/bugs/48/

The code below fails on F_safe() call while it does work with F() call:

$ cat test.cpp
#include <blitz/array.h>
using namespace blitz;
using namespace std;

template <class T1, class T2>
auto F(const T1 &a1, const T2 &a2)
-> decltype(a1 * a2)
{ return a1 * a2; }

template <class T1, class T2>
auto F_safe(const T1 &a1, const T2 &a2)
-> decltype(safeToReturn(a1 * a2))
{ return safeToReturn(a1 * a2); }

int main()
{
Range i(0, 10);
Array<double,1>
A(Range(-1, 11)),
B(Range(-1, 11)),
C(Range( 0, 11));

cerr << "F() ..." << endl;
A(i) = F(B(i), C(i));
cerr << "F_safe() ..." << endl;
A(i) = F_safe(B(i), C(i));
}

$ g++ -DBZ_DEBUG -std=c++11 test.cpp -lblitz
$ ./a.out
F() ...
F_safe() ...
/usr/local/include/blitz/bounds.h:71 Two array operands have different
lower bounds: in rank 0, the bounds are -1 and 0

a.out: /usr/local/include/blitz/bounds.h:72: static int
blitz::bounds::compute_lbound(int, int, int): Assertion `0' failed.
Aborted