<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/75782>75782</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[libcxx] std::normal_distribution may need a static assertion
</td>
</tr>
<tr>
<th>Labels</th>
<td>
libc++
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
GuF-veg
</td>
</tr>
</table>
<pre>
Consider this code:

Using clang + llvm + libc++ toolchain (version: 17.0.6), this code will compile successfully.
But it will lead to runtime errors:


Refer to cppreference, the template parameter of std::normal_distribution must be a float point type. In another word, it must be float, double or long double, otherwise it will lead to a **Undefined Behaviour**.
I compile this code with GCC-13.2.0, it will arise a compilation error:

The reason is that there is a **static_assert** in GCC STL library random.h:

But there isn't a static_assert in LLVM Libc++ library normal_distribution.h:

So I think it may be a good idea to add a static assertion in LLVM library, in this way we can avoid a lot of latent errors.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyslc1u5DYMx59GcyFk2LRlyYc55ANZLJBeuru9LmSJHqv1SANJTnbevpAnybTZBYoCOVmWTNI_8k9Kp-QOnmjPxC0T9zu95jnE_af1gT_RYTcGe97fBZ-cpQh5dglMsMTaG1bfs_qGYcPEbcPEPUM153xK5QgfGD4cXJ7XsTLhyPBhWZ5eH_wUw59kMsMHnRLlxPBBdALbuu7LnhyRkAYuusHwDkfBBzV2vEfdYduNxuiG4XAJ_y05fwCzaH8AhrdQ_F8WbjQMb8syh7CYWTsPDNUTxeSCZ-0NNLKqq764wrsrGTy7ZQETjie3EKTVGEppWpflXF1C3q4ZXL58tpC2kAPE1Wd3JKAYQ0zvkoMfmByh-l4OQ88noxTvpBj5aFXLddMPOLbYCbwm5xK-_cjaTMp2oqv5ZI3mXd8IrkgRb0YrraxxHKR6C_87TUUyAczpFMuavKFLrgkyHU-LzgQnHfWRMkUIE6Rsyy-2Nz7Eo16-W5dydOOaXfBwXFOGkUDDtAS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