Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Boost. 1.91.0 regression: optional<bool> copy constructor broken

Open Beginner friendly
#146 1 comment 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
70/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
cpp

Research direction

Start in include/boost/optional/detail/union_optional.hpp at the two constructor locations linked in the issue, and reproduce the provided optional example. Compare which constructor is selected for the mutable copy and verify the three assertions after the change; the work is done when the empty optional remains empty.

Written by the indexing model from the issue text.

Description

bug

Consider the following code:

const boost::optional<bool> constValue;
assert(!constValue.has_value()); // succeeds
boost::optional<bool> mutableValue(constValue);
assert(!mutableValue.has_value()); // succeeds
boost::optional<bool> mutableCopy(mutableValue);
assert(!mutableCopy.has_value()); // fails

The reason is that the wrong constructor is taken for boost::optional(boost::optional&):
https://github.com/boostorg/optional/blob/88e2378c8a9a45d4617d9386619677038b392ff1/include/boost/optional/detail/union_optional.hpp#L391
instead of
https://github.com/boostorg/optional/blob/88e2378c8a9a45d4617d9386619677038b392ff1/include/boost/optional/detail/union_optional.hpp#L293.

Dominant language
C++
Stars
60
Forks
75
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from boostorg/optional

All issues in boostorg/optional

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.