You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
optional<bool>(optional<bool>) constructor is broken in 1.91 #151
It appears that changes to boost::optional in 1.91 introduced a bug in optional<bool>(optional<bool>) constructor similar to the one from LWG issue 3836. 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:
#include<optional>
#include<iostream>
#include<boost/optional.hpp>usingWHICH::optional;
template <classT>
std::ostream& print(std::ostream& s, const optional<T>& opt) {
return opt ? s << *opt : s << "--";
}
intmain() {
optional<bool> a;
optional<bool> b(a);
optional<bool> c(b);
print(std::cout, a) << "";
print(std::cout, b) << "";
print(std::cout, c) << std::endl;
return0;
}
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.
Activity
eltoder commentedon Apr 27, 2026
Duplicate of #146