[LLVMbugs] [Bug 24131] New: user-defined conversion function allows cast to reference

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Jul 15 07:39:33 PDT 2015


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: unassignedclangbugs at nondot.org
          Reporter: barry.revzin at gmail.com
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20150715/8ad425d2/attachment.html>


More information about the llvm-bugs mailing list