<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 - clang-cl allows dynamic_cast when /GR- is specified"
href="https://bugs.llvm.org/show_bug.cgi?id=46246">46246</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>clang-cl allows dynamic_cast when /GR- is specified
</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>Windows NT
</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>Frontend
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>zufuliu@163.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>cl /GR- test.cpp produces a warning: warning C4541: 'dynamic_cast' used on
polymorphic type 'B' with /GR-; unpredictable behavior may result
clang-cl /GR- test.cpp produces no warnings, while clang -fno-rtti test.cpp
produces a error: use of dynamic_cast requires -frtti
Since compiling without RTTI doesn't produce runnable code (the program crashed
inside dynamic_cast), I think clang-cl should emit a warning or error.
this is related to <a class="bz_bug_link
bz_status_NEW "
title="NEW - clang-cl incorrectly defines __cpp_rtti when /GR- is specified"
href="show_bug.cgi?id=46230">https://bugs.llvm.org/show_bug.cgi?id=46230</a>
test.cpp also at <a href="https://godbolt.org/z/C4HZtK">https://godbolt.org/z/C4HZtK</a>
#include <cstdio>
class B {
public:
virtual ~B() = default;
};
class D1 : public B {
public:
~D1() = default;
static void f(B *b) noexcept {
printf("enter D1::g()\n");
if (auto d = dynamic_cast<D1 *>(b)) {
printf("D1::g() after cast\n");
}
printf("exit D1::g()\n");
}
};
class D2 : public B {
public:
~D2() = default;
};
int main() {
B *b = new D1();
D1::f(b);
delete b;
return 0;
}</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>