std::convertible_to
have semantic requirement when To
is reference-to-function type?Section: 18.4.4 [concept.convertible] Status: New Submitter: S. B. Tam Opened: 2020-06-30 Last modified: 2020-07-12
Priority: 3
View other active issues in [concept.convertible].
View all other issues in [concept.convertible].
View all issues with New status.
Discussion:
18.4.4 [concept.convertible] p2:
Types
From
andTo
modelconvertible_to<From, To>
only if:
(2.1) —
To
is not an object or reference-to-object type, orstatic_cast<To>(f())
is equal totest(f)
.[…]
This requires the implicit and explicit conversions to produce equal results.
However, it seems that whenTo
is a reference-to-function type, this restriction does not apply.
This makes it possible to create a class that models convertible_to
, but produces different
results depending on the kind of conversion:
#include <concepts> int foo() { return 0; } int bar() { return 42; } using FT = int(); struct A { operator FT&() const { return foo; } explicit operator FT&() { return bar; } }; static_assert(std::convertible_to<A, FT&>); A a; FT& x = a; // x == foo auto y = static_cast<FT&>(a); // y == bar
[2020-07-12; Reflector prioritization]
Set priority to 3 after reflector discussions.
Proposed resolution: