Looks lie a bug: no implicit conversion from slice_array to valarray in 3.4.1 + libcpp

Hello, Cfe-dev.

I'm using clang 3.4.1 (FreeBSD-CURRENT system compiler) with
I'm compile very simple program, which uses <valarray>. Of course, it is
test case, I found this bug when try to compile qucs project on this system

============ test.cpp
#include <valarray>

int main(int argc, char *argv) {
        std::valarray<double> a(4, 10);
        std::valarray<double> b(4, 20);
        a *= b[std::slice(1,1,1)];
        return 0;
}

I’ve opened issue 20946 – Cannot multiply a valarray and a single element slice_array to track this.

I’m not sure if this is a bug in libc++, or an extension in libstdc++.
A quick look at the standard doesn’t show any implicit conversions from a single-element slice array (the result of 'b[std::slice(1,1,1)]’) to a double.

Thanks for the report.

— Marshall

I could be wrong (I'm not C++ guru), but looks like
slice_array<double> should be converted to valarray<double> in such
case with appropriate valarray's constructor (it isn't marked as
"explicit"), because there are appropriate "operator *=" in valarray
class to multiple two valarrays.

I want to note, that in real code I encounter this, slice was not
single-element, and it worked in gcc 4.8. Maybe, my trimmed example is
not very good (due to single-element slice, which could lead to
confusion).

- --
// Lev Serebryakov

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

I'm using clang 3.4.1 (FreeBSD-CURRENT system compiler) with I'm
compile very simple program, which uses <valarray>. Of course, it
is test case, I found this bug when try to compile qucs project
on this system ============ test.cpp #include <valarray>

int main(int argc, char *argv) { std::valarray<double> a(4,
10); std::valarray<double> b(4, 20); a *= b[std::slice(1,1,1)];
return 0; } =====================

I’ve opened issue 20946 – Cannot multiply a valarray and a single element slice_array to
track this.

I’m not sure if this is a bug in libc++, or an extension in
libstdc++. A quick look at the standard doesn’t show any implicit
conversions from a single-element slice array (the result of
'b[std::slice(1,1,1)]’) to a double.

Thanks for the report.

I could be wrong (I'm not C++ guru), but looks like
slice_array<double> should be converted to valarray<double> in such
case with appropriate valarray's constructor (it isn't marked as
"explicit"), because there are appropriate "operator *=" in valarray
class to multiple two valarrays.

Yes, that seems to be the case.
You’re welcome to add yourself to the bug, and then you’ll get notifications
as it is updated.

I want to note, that in real code I encounter this, slice was not
single-element, and it worked in gcc 4.8. Maybe, my trimmed example is
not very good (due to single-element slice, which could lead to
confusion).

Right. Noted.
Thanks again.

— Marshall