Uploaded image for project: 'C++ Standard Library'
  1. C++ Standard Library
  2. STDCXX-1061

std::valarray<>::operator&& () produces wrong result

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 4.2.1
    • Fix Version/s: 4.2.x, 4.3.x, 5.0.0
    • Component/s: 23. Containers
    • Environment:

      Solaris 10 and 11
      Red Hat Linux
      OpenSuSE Linux
      SunPro C++ 12.1, 12.2, 12.3

      Defect is independent of platform and/or compiler.

    • Patch Info:
      Patch Available
    • Regression:
      Regression, Unit Test Broken
    • Severity:
      Incorrect Behavior

      Description

      std::valarray<>::operator&& () produces wrong result:

      test.cc
      #include <iostream>
      #include <valarray>
      
      static const size_t maxlen = 10;
      
      void print(const std::valarray<bool>& v)
      {
          for (size_t i = 0; i < maxlen; ++i)
              std::cerr << v[i] << " ";
          std::cerr << std::endl;
      }
      
      int main()
      {
          int nonzero[maxlen] = { 0, 1, 0, 3, 0, -5, 0, -7, 0, -11 };
          int one = 1;
          int ret = 0;
          size_t i;
      
          std::valarray<int> v0 (nonzero, maxlen);
          std::valarray<bool> v3 (maxlen);
      
          for (i = 0; i < maxlen; i++)
              v3[i] = nonzero[i] && one;
      
          std::valarray<bool> v1 = std::operator&& (v0, one);
      
          for (i = 0; i < maxlen; i++)
          {
              if ((nonzero[i] && one) != v1[i])
                  ret = 1;
          }
      
          if (ret)
          {
              std::cerr << "expected: ";
              print (v3);
              std::cerr << "got: ";
              print (v1);
          }
      
          return ret;
      }
      

      1. Output from GCC 4.5.0:

      [steleman@darthvader][/src/steleman/programming/stdcxx-ss122/bugfixes-sunw/nothrow][02/08/2012 13:22:47][2463]>> ./v-gcc
      [steleman@darthvader][/src/steleman/programming/stdcxx-ss122/bugfixes-sunw/nothrow][02/08/2012 13:23:01][2464]>> echo $status
      0
      

      2. Output from SunPro C++ 12.2 with stlport4:

      [steleman@darthvader][/src/steleman/programming/stdcxx-ss122/bugfixes-sunw/nothrow][02/08/2012 13:23:02][2465]>> ./v-ss122-stlport
      [steleman@darthvader][/src/steleman/programming/stdcxx-ss122/bugfixes-sunw/nothrow][02/08/2012 13:23:08][2466]>> echo $status
      0
      

      3. Output from SunPro C++ 12.2 with our patched stdcxx:

      [steleman@darthvader][/src/steleman/programming/stdcxx-ss122/bugfixes-sunw/nothrow][02/08/2012 13:23:10][2467]>> ./v-ss122-stdcxx
      [steleman@darthvader][/src/steleman/programming/stdcxx-ss122/bugfixes-sunw/nothrow][02/08/2012 13:23:18][2468]>> echo $status
      0
      

      4. Output from Pathscale 4.0.12.1 (which didn't patch stdcxx):

      [steleman@darthvader][/src/steleman/programming/stdcxx-ss122/bugfixes-sunw/nothrow][02/08/2012 13:23:20][2469]>> ./v-pathscale
      expected: 0 1 0 1 0 1 0 1 0 1 
      got: 0 1 0 0 0 0 0 0 0 0 
      [steleman@darthvader][/src/steleman/programming/stdcxx-ss122/bugfixes-sunw/nothrow][02/08/2012 13:23:24][2470]>> echo $status
      1
      

      Patch for stdcxx 4.2.1 to follow shortly.

        Attachments

        1. stdcxx-1061.patch
          0.4 kB
          Stefan Teleman

          Activity

            People

            • Assignee:
              vitek Travis Vitek
              Reporter:
              steleman Stefan Teleman
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated: