<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - C-style cast wrongly falls back to reinterpret_cast when static_cast would choose deleted function"
href="https://bugs.llvm.org/show_bug.cgi?id=52199">52199</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>C-style cast wrongly falls back to reinterpret_cast when static_cast would choose deleted function
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C++
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>arthur.j.odwyer@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>Notice that this is NOT diagnostic-QoI issue #7103 a.k.a. #32065 (even though I
strongly support those diagnostics and wish Clang had them). This particular
bug report is actually Clang being non-conforming.
The relevant part of the Standard is here:
<a href="https://eel.is/c++draft/expr.cast#4.sentence-3">https://eel.is/c++draft/expr.cast#4.sentence-3</a>
<span class="quote">> If a conversion can be interpreted in more than one of the ways listed above,
> the interpretation that appears first in the list is used,
> even if a cast resulting from that interpretation is ill-formed.</span >
In each of these cases, a `static_cast` would work, but Clang prematurely sees
that it would end up calling a deleted function (either a deleted ctor or a
deleted conversion operator) and avoids it, proceeding to interpret the C-style
cast as a `reinterpret_cast`. The correct behavior (GCC/MSVC/EDG) is to select
the `static_cast`, smash into the deleted function, and error out.
// <a href="https://godbolt.org/z/e9EvrWYEP">https://godbolt.org/z/e9EvrWYEP</a>
struct A {};
struct B { B(A&) = delete; };
int main() {
A a;
B b = (const B&)a; // Clang accepts, GCC/MSVC/EDG reject
}
Similarly:
struct C {};
struct D { operator const C&() = delete; };
int main() {
D d;
C c = (const C&)d; // Clang accepts, GCC/MSVC/EDG reject
}
Similar but different (MSVC joins Clang in wrongly accepting):
struct A {};
struct I1 { operator A() const; };
struct I2 { operator A() const; };
struct D : I1, I2 {};
int main() {
D d;
A a = (const A&)d; // Clang/MSVC accept, GCC/EDG reject
}</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>