This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/46320] New: Operator[] dereference does not generate exception for empty string


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46320

           Summary: Operator[] dereference does not generate exception for
                    empty string
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: jerry@jerrycarter.org


This should generate an out_of_range exception according to section 21.3.4 of
the specification
<http://www.kuzbass.ru:8086/docs/isocpp/lib-strings.html#lib.string.access>.

[Test code]

#include <cstdio>
#include <string>
#include <iostream>
#include <cassert>

int main (int argc, const char * argv[]) {
    // insert code here...
    std::string x;
    x[0] = 'O'; // Should get out_of_range exception here.
    x[1] = 'd';
    x[2] = 'd';
    assert(x.length() == 0);
    assert(x.c_str() == std::string("Odd"));
    assert(x != std::string("Odd"));
    assert(x.data()[0] == 'O');
    assert(x.data()[1] == 'd');
    assert(x.data()[2] == 'd');
    assert(x.size() == 0);
    return 0;
}

[Compiler version]

GNU gdb 6.3.50-20050815 (Apple version gdb-1472) (Wed Jul 21 10:53:12 UTC 2010)
Copyright 2004 Free Software Foundation, Inc.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]