<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 - dynamic_cast to ambiguous derived class produces the wrong answer"
href="https://bugs.llvm.org/show_bug.cgi?id=33487">33487</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>dynamic_cast to ambiguous derived class produces the wrong answer
</td>
</tr>
<tr>
<th>Product</th>
<td>libc++abi
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</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>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>All Bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>arthur.j.odwyer@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org, mclow.lists@gmail.com
</td>
</tr></table>
<p>
<div>
<pre>This is similar to <a class="bz_bug_link
bz_status_NEW "
title="NEW - dynamic_cast to ambiguous base produces the wrong answer"
href="show_bug.cgi?id=33439">bug 33439</a>, but in that case we're casting between unrelated
types where the most derived type contains multiple (ambiguous) subobjects of
the destination type. In *this* case we're casting between related types — from
a base subobject to a derived type — where the source object is a subobject of
more than one object of the destination type. In both cases the symptom is
similar: dynamic_cast returns a pointer to the first such ambiguous subobject,
when it should be returning NULL.
#include <stdio.h>
struct Class1 { virtual ~Class1() {} };
struct Shared : public virtual Class1 {};
struct Class6 : public virtual Shared {};
struct Left : public Class6 {};
struct Right : public Class6 {};
struct Main : public Left, public Right {};
int main()
{
Main m;
Class1 *c1 = &m;
Class6 *c6 = dynamic_cast<Class6*>(c1);
printf("%p, should be nullptr\n", c6);
}</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>