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

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Jul 15 12:18:09 PDT 2015


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

Richard Smith <richard-llvm at metafoo.co.uk> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |richard-llvm at metafoo.co.uk
         Resolution|---                         |INVALID

--- Comment #2 from Richard Smith <richard-llvm at metafoo.co.uk> ---
[expr.static.cast]p4: "An expression e can be explicitly converted to a type T
using a static_cast of the form static_cast<T>(e) if the declaration T t(e); is
well-formed, for some invented temporary variable t (8.5)."

Thus we can reduce to a testcase not involving static_cast:

  struct B {};
  struct S { explicit operator B(); };
  B const &t(S{});

... which GCC and EDG reject, and Clang still accepts. And the above testcase
is valid:

Per 8.5.3/5.2.1.2, the relevant rules for selecting conversion functions are
those in 13.3.1.6, not those in 13.3.1.5.

Per 13.3.1.6, "For direct-initialization, those explicit conversion functions
that are not hidden within S and yield type “lvalue reference to cv2 T2” or
“cv2 T2” or “rvalue reference to cv2 T2”, respectively, where T2 is the same
type as T or can be converted to type T with a qualification conversion (4.4),
are also candidate functions."

So the explicit conversion operator is considered here, and both the
initialization and the static_cast are permitted.

-- 
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/80c7519f/attachment.html>


More information about the llvm-bugs mailing list