<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/84871>84871</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Clang does not report invalid arithmetic operations at compile time when doing `_Complex` math.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
tbaederr
</td>
</tr>
</table>
<pre>
For example:
```c++
static_assert(__imag(5.0j / 0) == __builtin_inf());
```
https://godbolt.org/z/59fqKv4Kc
This works without any diagnostics in Clang, but errors out in gcc.
There are actually a few tests in `tests/SemaCXX/complex-folding.cpp` that rely on this behavior, although they aren't as obvious as the example above:
https://github.com/llvm/llvm-project/blob/d02d8df0cd797342f7042440e07133e99ad5e0a2/clang/test/SemaCXX/complex-folding.cpp#L60-L99
In this example:
```c++
constexpr _Complex double D1 = {0.0, 0.0};
constexpr double D2 = __real(__builtin_inf() * D1);
static_assert(D2 == 1);
constexpr double D3 = __builtin_inf() * 0.0;
```
https://godbolt.org/z/dPME9To8d
(which is adapted and simplified from the test above), multiplying `inf` with `0` produces a `nan`, which is properly diagnosed when evaluating the initializer for `D3`, but not at al when evaluating `D2`. The `static_assert` proves that D2 is indeed `nan`.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycVE2PozgQ_TXOpTTIGBLgwKE7WaTVzEorbR_mFhW4Ap41mLVNujO_flUk_Tka7YfkBIzsqlev3isMwfQTUS2292J72OASB-fr2CJp8n7TOn2pG-eBnnCcLYnsTsiDkHdiJ6-rE-qe1_o1RIymO2II5KNQ5fFoRuyFKreJ_AZCNSCFqkBkB5Ed4HhsF2OjmY5mOglVClXxyu4_pLhuhxjnwPlVI1TTO906GxPne6Ga70I12-r01-dz_rm73V7_HwYT4NH5PwM8mji4JQJOF9AG-8mFaLoAZoK9xakXag_tEoG8dz4AHzUT9F2XvA9IngD518UFrb0AwokeIVKIazC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