From mboxrd@z Thu Jan 1 00:00:00 1970 From: Peter Schmid To: gdr@gcc.gnu.org Cc: gcc-prs@gcc.gnu.org Subject: Re: libstdc++/3247 Date: Tue, 26 Jun 2001 17:56:00 -0000 Message-id: <20010627005602.7227.qmail@sourceware.cygnus.com> X-SW-Source: 2001-06/msg01112.html List-Id: The following reply was made to PR libstdc++/3247; it has been noted by GNATS. From: Peter Schmid To: bkoz@gnu.org Cc: gcc-gnats@gcc.gnu.org, gcc-bugs@gcc.gnu.org Subject: Re: libstdc++/3247 Date: Wed, 27 Jun 2001 03:55:23 +0200 (CEST) This is a known (IMHO mis-) "feature" of the slice or gslice interface of the ISO standard. This is because the C++ standard library does not specify that valarray subsets provide the same operations as valarrays. Therefore, some ugly casts to the valarray type are needed. Please confer page 554 of "The C++ Standard Library" by Josuttis. For example, the following code does indeed compile. To get a working program, you have to dimension the (val)arrays, though. Hope this helps, Peter Schmid Source code tbkoz.C #include #include template void gnu_operator(T1, Param1 p1, Param2 p2) { std::operator*(p1, p2); } int main() { double dvar = 1.0; std::valarray val_d; std::slice slc; std::gslice gslc; std::valarray val_b; std::valarray val_sizet; gnu_operator(dvar, val_d, val_d); gnu_operator(dvar, val_d, static_cast > (val_d[slc])); gnu_operator(dvar, val_d, static_cast > (val_d[gslc]) ); gnu_operator(dvar, val_d, static_cast > (val_d[val_b])); gnu_operator(dvar, val_d, static_cast > (val_d[val_sizet])); // and so on... gnu_operator(dvar, static_cast > (val_d[slc]), static_cast > (val_d[slc])); return 0; }; Compiling tbkoz.C g++ -v tbkoz.C -W -Wall Reading specs from /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.0/specs Configured with: ../gcc/configure --enable-shared --disable-nls --enable-threads=posix --enable-languages=c,c++,f77,objc Thread model: posix gcc version 3.0 20010615 (prerelease) /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.0/cc1plus -v -D__GNUC__=3 -D__GNUC_MINOR__=0 -D__GNUC_PATCHLEVEL__=0 -D__ELF__ -Dunix -Dlinux -D__ELF__ -D__unix__ -D__linux__ -D__unix -D__linux -Asystem=posix -D__NO_INLINE__ -D__STDC_HOSTED__=1 -W -Wall -D_GNU_SOURCE -Acpu=i386 -Amachine=i386 -Di386 -D__i386 -D__i386__ -D__tune_i686__ -D__tune_pentiumpro__ tbkoz.C -D__GNUG__=3 -D__GXX_DEPRECATED -D__EXCEPTIONS -D__GXX_ABI_VERSION=100 -quiet -dumpbase tbkoz.C -W -Wall -version -o /tmp/cc6nIa8N.s GNU CPP version 3.0 20010615 (prerelease) (cpplib) (i386 Linux/ELF) GNU C++ version 3.0 20010615 (prerelease) (i686-pc-linux-gnu) compiled by GNU C version 3.0 20010615 (prerelease). ignoring nonexistent directory "/usr/local/i686-pc-linux-gnu/include" #include "..." search starts here: #include <...> search starts here: /usr/local/include/g++-v3 /usr/local/include/g++-v3/i686-pc-linux-gnu /usr/local/include/g++-v3/backward /usr/local/include /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.0/include /usr/include End of search list. /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.0/../../../../i686-pc-linux-gnu/bin/as -V -Qy -o /tmp/ccNiYQFr.o /tmp/cc6nIa8N.s GNU assembler version 2.11.90.0.15 (i686-pc-linux-gnu) using BFD version 2.11.90.0.15 /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.0/collect2 -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 /usr/lib/crt1.o /usr/lib/crti.o /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.0/crtbegin.o -L/usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.0 -L/usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.0/../../../../i686-pc-linux-gnu/lib -L/usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.0/../../.. /tmp/ccNiYQFr.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.0/crtend.o /usr/lib/crtn.o