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

std::valarray transcendentals use uninitialized storage

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 4.1.2, 4.1.3, 4.1.4
    • 4.2.0
    • 26. Numerics
    • None
    • all

    • Runtime Error

    Description

      The program below is expected to produce no output. When compiled with the latest trunk it produces output indicating that the valarray transcendental functions use uninitialized storage.

      $ cat t.cpp && make t && ./t
      #include <cstdio>
      #include <valarray>

      bool pass = true;

      struct S {
      const S* const self;
      S (): self (this) { }
      S (const S &s): self (this)

      { pass = pass && &s == s.self; }

      S (double): self (this) { }
      ~S ()

      { pass = pass && this == self; }

      operator double () const

      { pass = pass && this == self; return 1.0; }

      void operator=(const S &s) const

      { pass = pass && &s == s.self && this == self; }

      S operator- () const

      { pass = pass && this == self; return *this; }

      bool operator< (const S &s) const

      { pass = pass && &s == s.self && this == self; return false; }

      };

      int main ()
      {
      const S s;
      const std::valarray<S> a (2);

      #define TEST(fun, args) \
      pass = true; \
      fun args; \
      if (!pass) \
      std::fprintf (stderr, "std::%s uses uninitialized storage\n", #fun)

      TEST (abs, (a));
      TEST (acos, (a));
      TEST (asin, (a));
      TEST (atan, (a));
      TEST (atan2, (a, a));
      TEST (atan2, (a, s));
      TEST (atan2, (s, a));
      TEST (cos, (a));
      TEST (cosh, (a));
      TEST (exp, (a));
      TEST (log, (a));
      TEST (log10, (a));
      TEST (pow, (a, a));
      TEST (pow, (a, s));
      TEST (pow, (s, a));
      TEST (sin, (a));
      TEST (sinh, (a));
      TEST (sqrt, (a));
      TEST (tan, (a));
      TEST (tanh, (a));
      }
      gcc -c -I/build/sebor/dev/stdlib/include/ansi -D_RWSTDDEBUG -D_RWSTD_USE_CONFIG -I/build/sebor/dev/stdlib/include -I/build/sebor/gcc-4.1.0-11s/include -I/build/sebor/dev/stdlib/examples/include -pedantic -nostdinc++ -g -W -Wall -Wcast-qual -Winline -Wshadow -Wwrite-strings -Wno-long-long t.cpp
      gcc t.o -o t -L/build/sebor/gcc-4.1.0-11s/lib -lstd11s -lsupc++ -lm
      std::abs uses uninitialized storage
      std::acos uses uninitialized storage
      std::asin uses uninitialized storage
      std::atan uses uninitialized storage
      std::atan2 uses uninitialized storage
      std::atan2 uses uninitialized storage
      std::atan2 uses uninitialized storage
      std::cos uses uninitialized storage
      std::cosh uses uninitialized storage
      std::exp uses uninitialized storage
      std::log uses uninitialized storage
      std::log10 uses uninitialized storage
      std::pow uses uninitialized storage
      std::pow uses uninitialized storage
      std::pow uses uninitialized storage
      std::sin uses uninitialized storage
      std::sinh uses uninitialized storage
      std::sqrt uses uninitialized storage
      std::tan uses uninitialized storage
      std::tanh uses uninitialized storage

      Attachments

        Issue Links

          Activity

            People

              sebor Martin Sebor
              sebor Martin Sebor
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: