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

            Bug ID: 24131
           Summary: user-defined conversion function allows cast to
                    reference
           Product: clang
           Version: 3.6
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected]
    Classification: Unclassified

Consider the following code, slightly simplified from SO question
(http://stackoverflow.com/q/31428980/2069064):

#include <string>

struct S
{
    std::string s;
    explicit operator std::string() const { return s; }
};


int main() 
{
    static_cast<std::string const&>(S{"hi"});
}

According to [over.match.conv], the candidate conversion functions are those
that "yield type T or a type that can be converted to type T via a standard
conversion sequence." But S does not have a conversion function that yields
std::string const& and the conversion from std::string to std::string const& is
not a standard conversion sequence. This code should be rejected (which gcc
does).

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to