stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Martin Sebor (JIRA)" <j...@apache.org>
Subject [jira] Closed: (STDCXX-224) std::valarray::operator[](slice) broken
Date Sun, 14 Oct 2007 23:11:53 GMT

     [ https://issues.apache.org/jira/browse/STDCXX-224?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Martin Sebor closed STDCXX-224.
-------------------------------

    Resolution: Cannot Reproduce

The problem cannot be reproduced with any Apache stdcxx release.

> std::valarray::operator[](slice) broken
> ---------------------------------------
>
>                 Key: STDCXX-224
>                 URL: https://issues.apache.org/jira/browse/STDCXX-224
>             Project: C++ Standard Library
>          Issue Type: Bug
>          Components: 26. Numerics
>         Environment: all
>            Reporter: Martin Sebor
>            Assignee: Martin Sebor
>             Fix For: 4.2
>
>
> Moved from the Rogue Wave bug tracking database:
> ****Created By: sebor @ Mar 16, 2003 06:51:05 PM****
> Subject: CXX-DEV: Bug in valarray / slice_array?
> mario.konijnenburg@philips.com
> Date: 03/13/03
> next message: Martin Sebor: "Re: CXX-DEV: Bug in valarray / slice_array?"
> previous message: Dennis Handly: "Re: CXX-DEV: Suggestions re cause of crash when shl_load'ing"
> Next in thread: Martin Sebor: "Re: CXX-DEV: Bug in valarray / slice_array?"
> reply: Martin Sebor: "Re: CXX-DEV: Bug in valarray / slice_array?"
> Hello,
> The following program results in incorrect results:
> #include <valarray>
> #include <iostream>
> int main() {
>    int vals[] = {1,0};
>    const std::valarray<int> p( vals, 2 );
>    for ( int i =0; i<p.size(); i++ )
>       std::cout << "p:" << i << "=" << p[i] << std::endl;
>  
>    const std::valarray<int> r = p[ std::slice( 0, 0, 1 ) ];
>    for ( int i =0; i<r.size(); i++ )
>       std::cout << "r:" << i << "=" << r[i] << std::endl;
>    return 0;
> }
> Output:
> LT:tmp 223 0>aCC -AA -g1 -o val.hp val2.C
> LT:tmp 224 0>./val.hp
> p:0=1
> p:1=0
> r:0=0
> r:1=0
> A slice is specified with size 0. Therefore I expect that valarray 'r' is
> of size 0 and no output should
> appear for 'r'.
> Note that I make use of -const- valarrays. In that case a valarray is
> returned by valarray::operator[].
> The problem disappears when I remove the 'const's. In that case a
> slice_array is
> returned by valarray::operator[] and used to construct valarray 'r'. The
> output when 'const' is removed is:
> LT:tmp 226 0>./val.hp
> p:0=1
> p:1=0
> Compiler: aCC: HP ANSI C++ B3910B A.03.37
> Do I something wrong or is this a compiler / library bug?
> Thanks.
> Regards, Mario.
> Mario.Konijnenburg@philips.com
> Philips Research Laboratories; Electronic Design & Tools;
> Building WAY3.27, Prof. Holstlaan 4 Phone: +31 (0)40 2743728
> 5656 AA Eindhoven, The Netherlands Fax: +31 (0)40 2744626
>  _________________________________________________________________
>  To leave this mailing list, send mail to majordomo@cxx.cup.hp.com
>     with the message UNSUBSCRIBE cxx-dev
>  _________________________________________________________________
> ****Modified By: sebor @ Mar 16, 2003 06:59:07 PM****
> -------- Original Message --------
> Subject: [Fwd: Re: CXX-DEV: Bug in valarray / slice_array?]
> Date: Sun, 16 Mar 2003 18:49:46 -0700
> From: Martin Sebor <sebor@roguewave.com>
> Organization: Rogue Wave Software, Inc.
> To: Dennis Handly <dhandly@cup.hp.com>
> Dennis,
> Here's a fix for the bug if you want to incorporate it. From
> briefly looking at <valarray> I suspect that there are a ton
> of subtle and not so subtle bugs such as this one and even
> more efficiency improvements that could be made; a complete
> rewrite will probably be necessary to make the class(es)
> useful.
> Martin
> template <class _TypeT>
> inline valarray<_TypeT>
> valarray<_TypeT>::operator[] (slice __sl) const
> {
>      if (0 == __sl.size ())
>          return valarray<_TypeT>();
>      _RWSTD_ASSERT (__sl.start () < size ());
>      _RWSTD_ASSERT (0 != __sl.stride ());
>      const _RWSTD_SIZE_T __size =
>          size () < __sl.start () + __sl.size () * __sl.stride () ?
>          (size () - __sl.start ()) / __sl.stride () : __sl.size ();
>      _RWSTD_ASSERT (__size <= size ());
>      _RW::__rw_array <_TypeT> __tmp =
>          _RW::__rw_array <_TypeT>(_TypeT (), __size);
>      for (_RWSTD_SIZE_T __i = __sl.start (), __j = 0; __j != __size;
>           __i += __sl.stride (), ++__j)
>          __tmp [__j] = _C_array [__i];
>      return valarray<_TypeT>(__tmp);
> }
> -------- Original Message --------
> Subject: Re: CXX-DEV: Bug in valarray / slice_array?
> Date: Fri, 14 Mar 2003 11:53:24 -0700
> From: Martin Sebor <sebor@roguewave.com>
> Reply-To: cxx-dev@cxx.cup.hp.com
> Organization: Rogue Wave Software, Inc.
> To: cxx-dev@cxx.cup.hp.com
> References: 
> <OF74FFB7D1.4EE6E0B0-ONC1256CE8.00578BB4-C1256CE8.00588177@diamond.philips.com>
> mario.konijnenburg@philips.com wrote:
>  > Hello,
>  >
>  > The following program results in incorrect results:
>  >
> ...
>  >
>  > A slice is specified with size 0. Therefore I expect that valarray 
> 'r' is
>  > of size 0 and no output should
>  > appear for 'r'.
>  > Note that I make use of -const- valarrays. In that case a valarray is
>  > returned by valarray::operator[].
>  >
>  > The problem disappears when I remove the 'const's. In that case a
>  > slice_array is
>  > returned by valarray::operator[] and used to construct valarray 'r'. The
>  > output when 'const' is removed is:
>  > LT:tmp 226 0>./val.hp
>  > p:0=1
>  > p:1=0
>  >
>  > Compiler: aCC: HP ANSI C++ B3910B A.03.37
>  >
>  >
>  > Do I something wrong or is this a compiler / library bug?
> It's a bug in valarray::operator[](slice) const.
> Regards
> Martin

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message