`optional<bool>(optional<bool>)` constructor is broken in 1.91
- Dominant language
- HTML
- Stars
- 8.6k
- Forks
- 1.9k
- Avg merge
- 39m
- Merged PRs (30d)
- 2
Description
It appears that changes to `boost::optional` in 1.91 introduced a bug in `optional(optional)` constructor similar to the one from [LWG issue 3836](https://cplusplus.github.io/LWG/issue3836). That is, instead of copying the source optional, it converts it to a `bool` using its `operator bool` and stores that result in the new optional. This results in an optional that always has a value, which is equal to whether the source optional had a value.
Test case:
```c++
#include
#include
#include
using WHICH::optional;
template
std::ostream& print(std::ostream& s, const optional& opt) {
return opt ? s << *opt : s << "--";
}
int main() {
optional a;
optional b(a);
optional c(b);
print(std::cout, a) << " ";
print(std::cout, b) << " ";
print(std::cout, c) << std::endl;
return 0;
}
```
Compiling with `std::optional` gives the expected behavior:
```
$ g++ -DWHICH=std t.cc && ./a.out
-- -- --
```
Compiling with `boost::optional` from 1.91 shows the bug:
```
$ g++ -DWHICH=boost t.cc && ./a.out
-- 0 1
```
Earlier versions of boost worked the same way as `std::optional`.
Tested on linux with g++ version 13.3.0.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.