[llvm-bugs] [Bug 51764] New: The explicit conversion function shouldn't be considered in a model copy-initialization in reference binding

via llvm-bugs llvm-bugs at lists.llvm.org
Sun Sep 5 23:33:47 PDT 2021


https://bugs.llvm.org/show_bug.cgi?id=51764

            Bug ID: 51764
           Summary: The explicit conversion function shouldn't be
                    considered in a model copy-initialization in reference
                    binding
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++2a
          Assignee: unassignedclangbugs at nondot.org
          Reporter: xmh970252187 at gmail.com
                CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
                    llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk

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

Clang is wrong to accept this example, as per [dcl.init.ref#5.4.1] 

> If T1 or T2 is a class type and T1 is not reference-related to T2, user-defined conversions are considered using the rules for copy-initialization of an object of type “cv1 T1” by user-defined conversion ([dcl.init], [over.match.copy], [over.match.conv]); the program is ill-formed if the corresponding non-reference copy-initialization would be ill-formed. The result of the call to the conversion function, as described for the non-reference copy-initialization, is then used to direct-initialize the reference. For this direct-initialization, user-defined conversions are not considered.  

In the copy-initialization of an object, the explicit conversion function is
not a candidate, hence the copy-initialization is ill-formed, hence the
reference binding is also ill-formed.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210906/c185a68a/attachment.html>


More information about the llvm-bugs mailing list