path
is convertible from approximately everything under the sunSection: 31.12.6.5.1 [fs.path.construct] Status: C++17 Submitter: Tim Song Opened: 2016-05-10 Last modified: 2017-07-30
Priority: 1
View all issues with C++17 status.
Discussion:
The unconstrained template<class Source> path(const Source& source);
constructor defines an
implicit conversion from pretty much everything to path
. This can lead to surprising ambiguities in
overload resolution.
struct meow { operator const char *() const; }; std::ifstream purr(meow{});
because a meow
can be converted to either a path
or a const char*
by a user-defined
conversion, even though part of the stated goal of LWG 2676's P/R is to avoid "break[ing] user
code depending on user-defined automatic conversions to the existing argument types".
Previous resolution [SUPERSEDED]:
This wording is relative to N4582.
[Drafting note:
decay_t<Source>
handles both the input iterator case (31.12.6.4 [fs.path.req]/1.2) and the array case (31.12.6.4 [fs.path.req]/1.3). The level of constraints required is debatable; the following wording limits the constraint to "is abasic_string
or an iterator", but perhaps stronger constraints (e.g., aniterator_category
check in the second case, and/or avalue_type
check for both cases) would be desirable.]
Change 31.12.6.5.1 [fs.path.construct] as indicated:
template <class Source> path(const Source& source); template <class InputIterator> path(InputIterator first, InputIterator last);-4- Effects: Constructs an object of class
-?- Remarks: The first overload shall not participate in overload resolution unless eitherpath
, storing the effective range ofsource
(27.10.8.3) or the range[first, last)
inpathname
, converting format and encoding if required (27.10.8.2.1).Source
is a specialization ofbasic_string
or the qualified-iditerator_traits<decay_t<Source>>::value_type
is valid and denotes a type (13.10.3 [temp.deduct]).
[2016-05-28, Eric Fiselier comments suggests alternative wording]
Functions taking EcharT
or Source
parameter types often provide additional overloads with the
same arity and concrete types. In order to allow conversions to these concrete types in the interface we need to
explicitly disable the EcharT
and Source
overloads.
[2016-06-19, Eric and Tim improve the wording]
[2016-06, Oulu]
Voted to Ready 8-0 Monday morning in Oulu
Proposed resolution:
This wording is relative to N4594.
[Drafting note: Functions taking
EcharT
orSource
parameter types often provide additional overloads with the same arity and concrete types. In order to allow conversions to these concrete types in the interface we need to explicitly disable theEcharT
andSource
overloads.]
Change 31.12.3 [fs.req] as indicated:
-2-
Template parameters namedFunctions with template parameters namedEcharT
shall beEcharT
shall not participate in overload resolution unlessEcharT
is one of the encoded character types.
Insert a new paragraph between 31.12.6.4 [fs.path.req] p1 and p2 as indicated:
-?- Functions taking template parameters named
Source
shall not participate in overload resolution unless eitherSource
is a specialization ofbasic_string
or the qualified-iditerator_traits<decay_t<Source>>::value_type
is valid and denotes a possiblyconst
encoded character type (13.10.3 [temp.deduct]).