C++ Standard Library
  1. C++ Standard Library
  2. STDCXX-83

std::generate_n() assumes Size can be decremented

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 4.1.2
    • Fix Version/s: 4.1.3
    • Component/s: 25. Algorithms
    • Labels:
      None
    • Environment:

      all

      Description

      The requirement on the Size template argument to std::generate_n() in lib.alg.generate, p2 is that it be convertible to an integral type which does not imply that it be possible to decrement or otherwise modify its value. I.e., the program below is expected to compile successfully.

      $ cat t.cpp && nice make t
      #include <algorithm>

      struct Size {
      operator int()

      { return 0; }

      private:
      void operator=(Size&);
      };

      template void std::generate_n (int*, Size, int ());

      int main () { }
      eccp -c -I/build/sebor/dev/stdlib/include/ansi -D_RWSTDDEBUG -D_RWSTD_USE_CONFIG -I/build/sebor/eccp-3.6-11s/include -I/build/sebor/dev/stdlib/include -I/build/sebor/dev/stdlib/../rwtest -I/build/sebor/dev/stdlib/../rwtest/include -I/build/sebor/dev/stdlib/tests/include -A -x --template_directory=/build/sebor/eccp-3.6-11s/lib -g --display_error_number --remarks --diag_suppress 193,236,340,401,261,479,487,678,679,815 t.cpp
      "/build/sebor/dev/stdlib/include/algorithm", line 431: error #349: no operator
      "--" matches these operands
      operand types are: – Size
      for (; _n > 0; --n, ++_first)
      ^
      detected during instantiation of "void std::generate_n(_OutputIter,
      _Size, _Generator) [with _OutputIter=int *, _Size=Size,
      _Generator=int ()]" at line 9 of "t.cpp"

      1 error detected in the compilation of "t.cpp".

        Issue Links

          Activity

          No work has yet been logged on this issue.

            People

            • Assignee:
              Martin Sebor
              Reporter:
              Martin Sebor
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development