[tiny] basic_string(const charT*, size_type, const Allocator&) requires clause too restrictive
Nevin Liber

Created on 2012-12-19.00:00:00 last changed 74 months ago


Date: 2013-03-29.11:34:30

Proposed resolution:

  Requires: n < npos and either s shall not be a null pointer or n == 0.
Date: 2014-07-01.21:57:43

In n3485 21.4.2p6 (basic_string constructors and assignment operators), we have:

  basic_string(const charT* s, size_type n,
  const Allocator& a = Allocator());
  Requires: s shall not be a null pointer and n < npos.
That requires clause is too restrictive; s can be a null pointer when n==0. A (simplified) use case I have seen:
  std::string StringFromVector(std::vector<char> const& vc)
  { return std::string(vc.data(), vc.size()); }
Since a conforming implementation can return a null pointer for vc.data() when vc.size() == 0. I don't see any reason to disallow this construct, especially since it takes a Standards expert to see that this is possibly illegal, but not std::string(vc.data(), vc.data() + vc.size()).

This is likely to go onto the LEWG's plate.

Bristol 2013: Defer to LEWG.

Filed as LEWG Bug 39, closing as Resolved on the EWG side.

Date User Action Args
2014-07-01 21:57:43adminsetstatus: ready -> open
2013-04-28 20:20:29adminsetstatus: open -> ready
2013-03-29 11:34:30adminsetmessages: + msg56
2012-12-19 00:00:00admincreate