[libc++][test] rand.dist.bern.negbin/eval.pass.cpp constructs with `p == 1`, which has undefined behavior
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
This test constructs a `negative_binomial_distribution` from `(40, 1)`:
https://github.com/llvm/llvm-project/blob/f6c86bd69d92e82096fa98f8e38bb7ebf4ce9274/libcxx/test/std/numerics/rand/rand.dist/rand.dist.bern/rand.dist.bern.negbin/eval.pass.cpp#L167-L170
But [N5032](https://isocpp.org/files/papers/N5032.pdf) \[rand.dist.bern.negbin\]/1 notes that this has undefined behavior: "\[*Note 1:* This implies that *P(i | k, p)* is undefined when `p == 1`. *- end note*\]"
This test should be fixed to pass an argument for `p` that's strictly less than `1.0`.
(There's a wording defect here that I was unable to get LWG to fix. /2's Preconditions specify "0 < `p` <= 1", but it makes absolutely no sense for the Preconditions to allow `p == 1` when any use of the resulting distribution will be doomed to have undefined behavior. The arguments against changing this were uncompelling but it wasn't worth my time to push further. In any event, the fact that the Preconditions allow this, doesn't make the resulting distribution usage any more valid.)
Contributor guide
Research direction
Open libcxx/test/std/numerics/rand/rand.dist/rand.dist.bern/rand.dist.bern.negbin/eval.pass.cpp around lines 167–170 and inspect the negative_binomial_distribution construction. Change the test input so p is strictly less than 1.0, then run this test to confirm it no longer exercises undefined behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100