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

std::valarray::sum does not work correctly for udt that has nonzero default value

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 4.2.0, 4.2.1
    • Fix Version/s: 4.3.0
    • Component/s: 26. Numerics
    • Labels:
      None
    • Severity:
      Incorrect Behavior

      Description

      #include <cassert>
      #include <valarray>

      struct S
      {
      // this ctor should not be required
      S ()
      : value (21)
      {
      }

      S (int v)
      : value (v)
      {
      }

      S (const S& rhs)
      : value (rhs.value)
      {
      }

      S& operator+= (const S& rhs)

      { value += rhs.value; return *this; }

      int value;
      };

      int main ()
      {
      const std::valarray<S> b (S (10), 1); // 10 elements with value 1
      assert (b.sum ().value == 10);

      return 0;
      }

      The wording in the standard seems to imply that the returned value should be a copy of one of the elements, and that op+= should be called on all of the other elements. If this is the case, then this an additional issue that would be detectable in user code [the user can count how many times the op+= is invoked]. This issue may apply to the min() and max() methods as well.

        Attachments

          Activity

            People

            • Assignee:
              sebor Martin Sebor
              Reporter:
              vitek Travis Vitek
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:

                Time Tracking

                Estimated:
                Original Estimate - 2h
                2h
                Remaining:
                Remaining Estimate - 2h
                2h
                Logged:
                Time Spent - Not Specified
                Not Specified