Title
Undefined behavior without proper requirements on basic_string constructors
Status
c++14
Section
[string.cons]
Submitter
Juan Soulie

Created on 2013-01-17.00:00:00 last changed 125 months ago

Messages

Date: 2013-09-29.10:16:57

Proposed resolution:

This wording is relative to N3485.

  1. Change [string.cons]/6 as indicated:

    basic_string(const charT* s, size_type n, const Allocator& a = Allocator());
    

    -6- Requires: s shall not be a null pointer and n < npospoints to an array of at least n elements of charT.

  2. Change [string.cons]/8 as indicated:

    basic_string(const charT* s, const Allocator& a = Allocator());
    

    -8- Requires: s shall not be a null pointerpoints to an array of at least traits::length(s) + 1 elements of charT.

Date: 2013-09-15.00:00:00

[ 2013-09-29, Bristol ]

Apply to the Working Paper

Date: 2013-04-15.00:00:00

[ 2013-04-18, Bristol ]

Move to Ready

Date: 2013-03-15.00:00:00

[ 2013-03-15 Issues Teleconference ]

Moved to Review.

The resolution could be worded more cleanly, and there is some concern about redundancy between Requirements and Effects clauses. Consensus that we do want to say something like this for the Requirements though.

Date: 2013-01-17.00:00:00

In [string.cons], I believe tighter requirements should be imposed on basic_string's constructors taking an s argument (or, a behavior should be provided for the undefined cases). These requirements are properly stated in the other members functions taking s arguments (append, assign, insert,...).

basic_string(const charT* s, size_type n, const Allocator& a = Allocator());

Relative to N3485, [string.cons]/6 says "Requires: s shall not be a null pointer and n < npos", where it should say: "Requires: s points to an array of at least n elements of charT"

basic_string(const charT* s, const Allocator& a = Allocator());

[string.cons]/8 says "Requires: s shall not be a null pointer.", where it should say: "Requires: s points to an array of at least traits::length(s) + 1 elements of charT"

Daniel:

I think that [res.on.arguments] p1 b2 basically requires this already, but the wording is indeed worth improving it.

History
Date User Action Args
2014-02-20 13:20:35adminsetstatus: wp -> c++14
2013-09-29 10:16:57adminsetmessages: + msg6652
2013-09-29 10:16:57adminsetstatus: voting -> wp
2013-09-23 13:24:31adminsetstatus: ready -> voting
2013-04-18 22:58:13adminsetmessages: + msg6467
2013-04-18 22:58:13adminsetstatus: review -> ready
2013-03-18 14:33:00adminsetmessages: + msg6443
2013-03-18 13:02:36adminsetstatus: new -> review
2013-03-12 20:31:03adminsetmessages: + msg6381
2013-01-17 00:00:00admincreate