2822. Resolution for LWG 2742 introduces ambiguities

Section: 24.3.2.2 [string.cons] Status: NAD Submitter: Jonathan Wakely Opened: 2016-11-15 Last modified: 2017-01-30

Priority: Not Prioritized

View all other issues in [string.cons].

View all issues with NAD status.

Discussion:

The new constructor added for LWG 2742 causes an ambiguity when attempting to construct from a (non-const) char*

char s[] = "whoops"; 
std::string str(s, 2, 4);

This is the same problem discussed in 2758, and the fix is the same: disable that new constructor if T is convertible to const_pointer, so that the old constructor is used instead.

Previous resolution [SUPERSEDED]:

This wording is relative to N4606.

  1. Modify the new basic_string(const T& t, size_type pos, size_type n, const Allocator& a = Allocator()); constructor in 24.3.2.2 [string.cons] as shown:

    template<class T>
    basic_string(const T& t, size_type pos, size_type n, const Allocator& a = Allocator());
    

    -?- Effects: Creates a variable, sv, as if by basic_string_view<charT, traits> sv = t; and then behaves the same as:

    basic_string(sv.substr(pos, n), a)
    

    -?- Remarks: This constructor shall not participate in overload resolution unless is_convertible_v<const T&, basic_string_view<charT, traits>> is true and is_convertible_v<const T&, const charT*> is false.

[2016-12-21, Jonathan comments and reommends NAD]

Tim Song pointed out that this constructor isn't ambiguous, and I can no longer reproduce the errors I was getting, so I think this issue should be resolved NAD. The code snippet in the issue discussion compiles OK without the proposed change.

[2017-01-27 Telecon]

NAD

Proposed resolution: