<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/57058>57058</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
noexcept(typeid(x)) incorrectly evaluates to false when x is an lvalue of a polymorphic type
</td>
</tr>
<tr>
<th>Labels</th>
<td>
c++,
clang:frontend
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
miyuki
</td>
</tr>
</table>
<pre>
Consider the following code:
```C++
#include <typeinfo>
struct B { virtual void mf() {} };
struct D : B {};
D d, &r = d;
int main() {
static_assert(noexcept(typeid(d)));
static_assert(noexcept(typeid(r)));
}
```
Clang (recent trunk, version 16 under development) produces the following errors:
```
$ clang -std=c++17 test.cc
<source>:8:25: warning: expression with side effects has no effect in an unevaluated context [-Wunevaluated-expression]
static_assert(noexcept(typeid(d)));
^
<source>:8:2: error: static assertion failed due to requirement 'noexcept(typeid(d))'
static_assert(noexcept(typeid(d)));
^ ~~~~~~~~~~~~~~~~~~~
<source>:9:28: warning: expression with side effects has no effect in an unevaluated context [-Wunevaluated-expression]
static_assert(noexcept(typeid(r)));
^
<source>:9:5: error: static assertion failed due to requirement 'noexcept(typeid(r))'
static_assert(noexcept(typeid(r)));
^ ~~~~~~~~~~~~~~~~~~~
2 warnings and 2 errors generated.
Compiler returned: 1
```
According to C++17 [except.spec]/6, a typeid expression is potentially-throwing only if typeid is applied to a possibly parenthesized built-in unary * operator applied to a pointer to a polymorphic class type. I.e., FWIW, the code is well-formed.
GCC accepts the code without errors.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzFVd1u2zoMfhr7Rohhy_FPLnyRn_ZgT9DLQZHpRJsieZKcJufpR9rJknZdgdMVOIZsS6Io8uMnkVvbnpu1NV614FjYA-us1vZZmR2TtoUoX0bpJkqv3zKd2jriK2rTLM-VkXpogUX5Opx7UKazUf5wr-qDG2RgKxZVK3ZULgxCs6NVLTt0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