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

std::vector<bool>::at() throws the wrong exception

    Details

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

      Solaris 10 and 11
      RedHat Linux, OpenSuSE Linux

      Defect is independent of platform and/or compiler

    • Patch Info:
      Patch Available
    • Severity:
      Incorrect Behavior

      Description

      The std::vector<bool>::at() specialization throws the wrong exception:

      test.cc
      #include <iostream>
      #include <vector>
      #include <stdexcept>
      
      static const size_t maxlen = 10;
      
      int main()
      {
          size_t i;
          bool b;
          int r;
          int ret = 0;
          int x = 0;
      
          std::vector<int> vi(maxlen, 1);
          std::vector<bool> vb(maxlen, false);
      
          try
          {
              r = vi.at (12);
          }
          catch (std::out_of_range& e)
          {
              std::cerr << "std::vector<int>::at(12): OK" << std::endl;
              ++x;
          }
          catch (std::exception& e)
          {
              std::cerr << "std::vector<int>::at(12): wrong exception: "
                      << e.what() << std::endl;
              ++ret;
              ++x;
          }
          catch ( ... )
          {
              std::cerr << "std::vector<int::>at(12): wrong exception!"
                      << std::endl;
              ++ret;
              ++x;
          }
      
          try
          {
              b = vb.at(12);
          }
          catch (std::out_of_range& e)
          {
              std::cerr << "std::vector<bool>::at(12): OK" << std::endl;
              ++x;
          }
          catch (std::exception& e)
          {
              std::cerr << "std::vector<bool>::at(12): wrong exception: "
                      << e.what() << std::endl;
              ++ret;
              ++x;
          }
          catch ( ... )
          {
              std::cerr << "std::vector<boolt>::at(12): wrong exception!"
                          << std::endl;
              ++ret;
              ++x;
          }
      
          if (x == 0)
          {
              std::cerr << "no exception was thrown" << std::endl;
              ++ret;
          }
      
          return ret;
      }
      

      1. Output from GCC 4.5.0 on OpenSuSE Linux 11.3:

      [steleman@darthvader][/src/steleman/programming/stdcxx-ss122/bugfixes-sunw/vector.bool][02/16/2012 15:37:04][1028]>> ./test-gcc
      std::vector<int>::at(12): OK
      std::vector<bool>::at(12): OK
      [steleman@darthvader][/src/steleman/programming/stdcxx-ss122/bugfixes-sunw/vector.bool][02/16/2012 15:37:16][1029]>> echo $status
      0
      

      2. Output from SunPro C++ 12.2 with libCstd (default):

      [steleman@darthvader][/src/steleman/programming/stdcxx-ss122/bugfixes-sunw/vector.bool][02/16/2012 15:37:25][1032]>> ./test-cstd
      std::vector<int>::at(12): OK
      std::vector<bool>::at(12): OK
      [steleman@darthvader][/src/steleman/programming/stdcxx-ss122/bugfixes-sunw/vector.bool][02/16/2012 15:37:29][1033]>> echo $status
      0
      

      3. Output from Intel C++ 12.10:

      [steleman@darthvader][/src/steleman/programming/stdcxx-ss122/bugfixes-sunw/vector.bool][02/16/2012 15:39:33][1053]>> ./test-icc 
      std::vector<int>::at(12): OK
      std::vector<bool>::at(12): OK
      [steleman@darthvader][/src/steleman/programming/stdcxx-ss122/bugfixes-sunw/vector.bool][02/16/2012 15:39:36][1054]>> echo $status
      0
      

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

      [steleman@darthvader][/src/steleman/programming/stdcxx-ss122/bugfixes-sunw/vector.bool][02/16/2012 15:37:31][1034]>> ./test-stdcxx
      std::vector<int>::at(12): OK
      std::vector<bool>::at(12): OK
      [steleman@darthvader][/src/steleman/programming/stdcxx-ss122/bugfixes-sunw/vector.bool][02/16/2012 15:37:35][1035]>> echo $status
      0
      

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

      [steleman@darthvader][/src/steleman/programming/stdcxx-ss122/bugfixes-sunw/vector.bool][02/16/2012 15:37:37][1036]>> ./test-pathscale
      std::vector<int>::at(12): OK
      std::vector<bool>::at(12): wrong exception: /opt/pathscale/ekopath-4.0.12.1/include/4.0.12.1/stl/vector:1236: std::vector<bool, _Allocator>::reference std::vector<bool, _Allocator>::at(typename _Allocator::size_type) [with _Allocator = std::allocator<bool>]: length error: size 12 out of range [0, 10)
      [steleman@darthvader][/src/steleman/programming/stdcxx-ss122/bugfixes-sunw/vector.bool][02/16/2012 15:37:42][1037]>> echo $status
      1
      
      1. stdcxx-1062.patch
        1 kB
        Stefan Teleman

        Activity

        Stefan Teleman created issue -
        Stefan Teleman made changes -
        Field Original Value New Value
        Attachment stdcxx-1062.patch [ 12514879 ]
        Stefan Teleman made changes -
        Patch Info Patch Available [ 10042 ]
        Stefan Teleman made changes -
        Description The std::vector<bool>::at() specialization throws the wrong exception:

        {code:title=test.cc|borderStyle=solid}
        #include <iostream>
        #include <vector>
        #include <stdexcept>

        static const size_t maxlen = 10;

        int main()
        {
            size_t i;
            bool b;
            int r;
            int ret = 0;
            int x = 0;

            std::vector<int> vi(maxlen, 1);
            std::vector<bool> vb(maxlen, false);

            try
            {
                r = vi.at (12);
            }
            catch (std::out_of_range& e)
            {
                std::cerr << "std::vector<int>::at(12): OK" << std::endl;
                ++x;
            }
            catch (std::exception& e)
            {
                std::cerr << "std::vector<int>::at(12): wrong exception: "
                        << e.what() << std::endl;
                ++ret;
                ++x;
            }
            catch ( ... )
            {
                std::cerr << "std::vector<int::>at(12): wrong exception!"
                        << std::endl;
                ++ret;
                ++x;
            }

            try
            {
                b = vb.at(12);
            }
            catch (std::out_of_range& e)
            {
                std::cerr << "std::vector<bool>::at(12): OK" << std::endl;
                ++x;
            }
            catch (std::exception& e)
            {
                std::cerr << "std::vector<bool>::at(12): wrong exception: "
                        << e.what() << std::endl;
                ++ret;
                ++x;
            }
            catch ( ... )
            {
                std::cerr << "std::vector<boolt>::at(12): wrong exception!"
                            << std::endl;
                ++ret;
                ++x;
            }

            if (x == 0)

            {
                std::cerr << "no exception was thrown" << std::endl;
                ++ret;
            }

            return ret;
        }
        {code}

        1. Output from GCC 4.5.0 on OpenSuSE Linux 11.3:
        {noformat}
        [steleman@darthvader][/src/steleman/programming/stdcxx-ss122/bugfixes-sunw/vector.bool][02/16/2012 15:37:04][1028]>> ./test-gcc
        std::vector<int>::at(12): OK
        std::vector<bool>::at(12): OK
        [steleman@darthvader][/src/steleman/programming/stdcxx-ss122/bugfixes-sunw/vector.bool][02/16/2012 15:37:16][1029]>> echo $status
        0
        {noformat}

        2. Output from SunPro C++ 12.2 with libCstd (default):
        {noformat}
        [steleman@darthvader][/src/steleman/programming/stdcxx-ss122/bugfixes-sunw/vector.bool][02/16/2012 15:37:25][1032]>> ./test-cstd
        std::vector<int>::at(12): OK
        std::vector<bool>::at(12): OK
        [steleman@darthvader][/src/steleman/programming/stdcxx-ss122/bugfixes-sunw/vector.bool][02/16/2012 15:37:29][1033]>> echo $status
        0
        {noformat}

        3. Output from Intel C++ 12.10:
        {noformat}
        [steleman@darthvader][/src/steleman/programming/stdcxx-ss122/bugfixes-sunw/vector.bool][02/16/2012 15:39:33][1053]>> ./test-icc
        std::vector<int>::at(12): OK
        std::vector<bool>::at(12): OK
        [steleman@darthvader][/src/steleman/programming/stdcxx-ss122/bugfixes-sunw/vector.bool][02/16/2012 15:39:36][1054]>> echo $status
        0
        {noformat}

        4. Output from SunPro C++ 12.2 with our patched stdcxx:
        {noformat}
        [steleman@darthvader][/src/steleman/programming/stdcxx-ss122/bugfixes-sunw/vector.bool][02/16/2012 15:37:31][1034]>> ./test-stdcxx
        std::vector<int>::at(12): OK
        std::vector<bool>::at(12): OK
        [steleman@darthvader][/src/steleman/programming/stdcxx-ss122/bugfixes-sunw/vector.bool][02/16/2012 15:37:35][1035]>> echo $status
        0
        {noformat}

        5. Output from Pathscale 4.0.12.1 (which didn't patch stdcxx):
        {noformat}
        [steleman@darthvader][/src/steleman/programming/stdcxx-ss122/bugfixes-sunw/vector.bool][02/16/2012 15:37:37][1036]>> ./test-pathscale
        std::vector<int>::at(12): OK
        std::vector<bool>::at(12): wrong exception: /opt/pathscale/ekopath-4.0.12.1/include/4.0.12.1/stl/vector:1236: std::vector<bool, _Allocator>::reference std::vector<bool, _Allocator>::at(typename _Allocator::size_type) [with _Allocator = std::allocator<bool>]: length error: size 12 out of range [0, 10)
        [steleman@darthvader][/src/steleman/programming/stdcxx-ss122/bugfixes-sunw/vector.bool][02/16/2012 15:37:42][1037]>> echo $status
        1
        {noformat}

        The std::vector<bool>::at() specialization throws the wrong exception:

        {code:title=test.cc|borderStyle=solid}
        #include <iostream>
        #include <vector>
        #include <stdexcept>

        static const size_t maxlen = 10;

        int main()
        {
            size_t i;
            bool b;
            int r;
            int ret = 0;
            int x = 0;

            std::vector<int> vi(maxlen, 1);
            std::vector<bool> vb(maxlen, false);

            try
            {
                r = vi.at (12);
            }
            catch (std::out_of_range& e)
            {
                std::cerr << "std::vector<int>::at(12): OK" << std::endl;
                ++x;
            }
            catch (std::exception& e)
            {
                std::cerr << "std::vector<int>::at(12): wrong exception: "
                        << e.what() << std::endl;
                ++ret;
                ++x;
            }
            catch ( ... )
            {
                std::cerr << "std::vector<int::>at(12): wrong exception!"
                        << std::endl;
                ++ret;
                ++x;
            }

            try
            {
                b = vb.at(12);
            }
            catch (std::out_of_range& e)
            {
                std::cerr << "std::vector<bool>::at(12): OK" << std::endl;
                ++x;
            }
            catch (std::exception& e)
            {
                std::cerr << "std::vector<bool>::at(12): wrong exception: "
                        << e.what() << std::endl;
                ++ret;
                ++x;
            }
            catch ( ... )
            {
                std::cerr << "std::vector<boolt>::at(12): wrong exception!"
                            << std::endl;
                ++ret;
                ++x;
            }

            if (x == 0)
            {
                std::cerr << "no exception was thrown" << std::endl;
                ++ret;
            }

            return ret;
        }
        {code}

        1. Output from GCC 4.5.0 on OpenSuSE Linux 11.3:
        {noformat}
        [steleman@darthvader][/src/steleman/programming/stdcxx-ss122/bugfixes-sunw/vector.bool][02/16/2012 15:37:04][1028]>> ./test-gcc
        std::vector<int>::at(12): OK
        std::vector<bool>::at(12): OK
        [steleman@darthvader][/src/steleman/programming/stdcxx-ss122/bugfixes-sunw/vector.bool][02/16/2012 15:37:16][1029]>> echo $status
        0
        {noformat}

        2. Output from SunPro C++ 12.2 with libCstd (default):
        {noformat}
        [steleman@darthvader][/src/steleman/programming/stdcxx-ss122/bugfixes-sunw/vector.bool][02/16/2012 15:37:25][1032]>> ./test-cstd
        std::vector<int>::at(12): OK
        std::vector<bool>::at(12): OK
        [steleman@darthvader][/src/steleman/programming/stdcxx-ss122/bugfixes-sunw/vector.bool][02/16/2012 15:37:29][1033]>> echo $status
        0
        {noformat}

        3. Output from Intel C++ 12.10:
        {noformat}
        [steleman@darthvader][/src/steleman/programming/stdcxx-ss122/bugfixes-sunw/vector.bool][02/16/2012 15:39:33][1053]>> ./test-icc
        std::vector<int>::at(12): OK
        std::vector<bool>::at(12): OK
        [steleman@darthvader][/src/steleman/programming/stdcxx-ss122/bugfixes-sunw/vector.bool][02/16/2012 15:39:36][1054]>> echo $status
        0
        {noformat}

        4. Output from SunPro C++ 12.2 with our patched stdcxx:
        {noformat}
        [steleman@darthvader][/src/steleman/programming/stdcxx-ss122/bugfixes-sunw/vector.bool][02/16/2012 15:37:31][1034]>> ./test-stdcxx
        std::vector<int>::at(12): OK
        std::vector<bool>::at(12): OK
        [steleman@darthvader][/src/steleman/programming/stdcxx-ss122/bugfixes-sunw/vector.bool][02/16/2012 15:37:35][1035]>> echo $status
        0
        {noformat}

        5. Output from Pathscale 4.0.12.1 (which didn't patch stdcxx):
        {noformat}
        [steleman@darthvader][/src/steleman/programming/stdcxx-ss122/bugfixes-sunw/vector.bool][02/16/2012 15:37:37][1036]>> ./test-pathscale
        std::vector<int>::at(12): OK
        std::vector<bool>::at(12): wrong exception: /opt/pathscale/ekopath-4.0.12.1/include/4.0.12.1/stl/vector:1236: std::vector<bool, _Allocator>::reference std::vector<bool, _Allocator>::at(typename _Allocator::size_type) [with _Allocator = std::allocator<bool>]: length error: size 12 out of range [0, 10)
        [steleman@darthvader][/src/steleman/programming/stdcxx-ss122/bugfixes-sunw/vector.bool][02/16/2012 15:37:42][1037]>> echo $status
        1
        {noformat}

        Farid Zaripov made changes -
        Assignee Farid Zaripov [ farid ]
        Farid Zaripov made changes -
        Status Open [ 1 ] In Progress [ 3 ]
        Farid Zaripov made changes -
        Status In Progress [ 3 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]

          People

          • Assignee:
            Farid Zaripov
            Reporter:
            Stefan Teleman
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development