tomaszkam / date

A date and time library based on the C++11/14/17 <chrono> header
Other
0 stars 0 forks source link

[LWG3235] parse manipulator without abbrevation is not callable #21

Closed tomaszkam closed 5 years ago

tomaszkam commented 5 years ago

Original comment:

replacing nullptr with std::declval<std::basic_string<CharT>*>() in the decltype of the parse overloads that don't take abbreviation but do take offset.

tomaszkam commented 5 years ago

I have little to no idea, why this change is required. It does not change the set of candidates, because std is already considered (due basic_istream). It is only related to precision of spec?

timsong-cpp commented 5 years ago

In from_stream abbrev is declared as a basic_string<charT, traits, Alloc>* where all three template parameters are in deduced contexts. Passing nullptr would cause deduction to fail.

tomaszkam commented 5 years ago

@timsong-cpp I have validated are from_stream overload from the [time.syn] (http://eel.is/c++draft/time.syn) and in case of the the abbrev argument uses 3 template paramters charT, traits and Alloc. Two of them (charT, traits) can be also deduced from basic_istream<charT, traits> and the third is consistently specified with default argument class Alloc = allocator<charT>.

As a consequence, no deduction from abbrev argument is needed for this overload to works correctly, so I fail to see the issue here. Am I missing something?

timsong-cpp commented 5 years ago

If you use nullptr, it's a straight-up mismatch and deduction fails right there. That you can deduce from the other arguments is irrelevant. See https://gcc.godbolt.org/z/ZIjfwV

tomaszkam commented 5 years ago

Thanks, I think I understand the issue now.

tomaszkam commented 5 years ago

Discussion: The parse overload that does not accept the abbreviation but does accept an offset, because the expression in the remarks clause: from_stream(declval<basic_istream<charT, traits>>(), fmt.c_str(), tp, nullptr, &offset) is not valid. This is caused by deduction failure for the basic_string<charT, traits, Alloc> from nullptr (see https://gcc.godbolt.org/z/ZIjfwV):

Drafting note: The proposed wording purposelly does not change the Remarks note to Constrain, to preserve constiency in this section.

Proposed wording: Apply the following changes to [time.parse]:

template<class charT, class traits, class Alloc, class Parsable>
  unspecified
    parse(const basic_string<charT, traits, Alloc>& fmt, Parsable& tp,
          minutes& offset);</code>

Remarks: This function shall not participate in overload resolution unless from_stream(declval<basic_istream<charT, traits>&>(), fmt.c_str(), tp, declval<std::basic_string<CharT, traits, Alloc>*>()nullptr, &offset) is a valid expression.

Returns: A manipulator that, when extracted from a basic­istream<charT, traits> is, calls from­stream(is, fmt.c_­str(), tp, static_cast<basic_string<CharT, traits, Alloc>*>(nullptr), &offset).