0

I have a very simple piece of code that treats matrices. Here's a short excerpt:

typedef boost::multiprecision::cpp_dec_float_100 SuperFloat;
typedef boost::numeric::ublas::matrix<SuperFloat> Matrix;
int function(Matrix& matrix){
  boost::numeric::ublas::permutation_matrix<std::size_t> pm(matrix.size1());
  int res = lu_factorize(matrix,pm); // this is a problem
  return res;
}

The code perfectly compiles and runs on my notebook, using g++ 5.2.0 and boost 1.58. However, when I try to compile the same code on my desktop machine at work, which is using gcc 4.9.2 and boost 1.53, I get a horrible error message (miles of template arguments), that ultimately comes to this:

cannot convert ‘boost::numeric::ublas::norm_inf 
# gazillions of template arguments
to type ‘const bool&’
std::max<S> (std::max<S> (norm_inf (e1), norm_inf (e2)), min_norm);
stl_algobase.h:261:5: note: template<class _Tp, class _Compare> const  _Tp& std::max(const _Tp&, const _Tp&, _Compare)
 max(const _Tp& __a, const _Tp& __b, _Compare __comp)

I'm a bit puzzled now. It seems like the template resolution of the arguments fails, which leads to the two arguments of max being of a different type. Unfortunately, I cannot explicitly typecast them, because the actual call causing the problem is buried somewhere in boost uBLAS.

Since I'm able to compile the same code with a different gcc and boost version on my notebook, there must be some sort of version issue here. Is there some particular change from gcc4.9 to 5.2 that affects the template resolution, or is there an issue with uBLAS in boost that causes this problem?

What is the suggested way of overcoming problems like these? While the obvious solution would be to update the gcc and boost on my work computer, it's certainly not very advisable to write code that relies on certain versions of gcc or boost to be used to compile it.

carsten
  • 1,315
  • 2
  • 13
  • 27
  • I couldn't get things to break with any 4.9+ gcc or clang and boost 1.53...1.59 http://coliru.stacked-crooked.com/a/b4f98060c53d55ad – sehe Aug 28 '15 at 19:45

1 Answers1

1

Is there some particular change from gcc4.9 to 5.2 that affects the template resolution, or is there an issue with uBLAS in boost that causes this problem?

Obviously, you've analyzed this yourself!

What is the suggested way of overcoming problems like these?

Yes, upgrade the boost version. Use a compiler version that is supported with that version of boost (Boost very liberally supports "older" compilers).

it's certainly not very advisable to write code that relies on certain versions of gcc or boost to be used to compile it.

Indeed, it isn't. So you write against a reasonably recent version that is going to be supported for a while.

The thing is that things don't "randomly" break. It's not like upgrading from 1.53 to 1.58 magically fixes your issue here, and breaks a zillion other things. Versions are incrementally improving.

So, if upgrading breaks something then you file a bug report because it's a regression.¹

In practice this doesn't happen very often because of existing tests. This is doubly true for any bugs that were actively fixed in previous versions, because many developers create the test-case as a reproducer before the fix, and the test stays around exactly to prevent a regress.


¹ in the event that a library makes a breaking change on purpose, this is always to be documented in the release notes. Most often, the old behaviour is still available for a transitional period, either in a different namespace or with a particular preprocessor define.

sehe
  • 374,641
  • 47
  • 450
  • 633