https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102212

            Bug ID: 102212
           Summary: The explicit conversion function should be permitted
                    in direct-initialization of a reference
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: xmh970252187 at gmail dot com
  Target Milestone: ---

struct D{};
D global;
struct A{
    explicit operator D(){
        return global;
    }
};
int main(){
    A a;
    D&& rf(a);
}

GCC rejects this example. According to [dcl.init.ref#5.3.2]  

> has a class type (i.e., T2 is a class type), where T1 is not 
> reference-related to T2, and can be converted to an rvalue or function lvalue 
> of type “cv3 T3”, where “cv1 T1” is reference-compatible with “cv3 T3” (see 
> [over.match.ref]),

And [over.match.ref#1] 

> “cv2 T2” and “rvalue reference to cv2 T2” (when initializing an rvalue 
> reference or an lvalue reference to function) 

> For direct-initialization, the permissible types for explicit conversion 
> functions are the members of R where T2 can be converted to type T with a 
> (possibly trivial) qualification conversion ([conv.qual]); otherwise there 
> are none.  

In this direct-initialization `D&& rf(a);`, `A::operator D()` should be a
candidate.

Reply via email to