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

Inconsistencies in std::optional<std::optional<FOO>> collapsing

Open
#292 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
cpp
Domain
compilers

Research direction

Start with the nested-optional parser expression in the issue and inspect how optional collapsing is currently documented and tested. Reproduce the "hallo there" case, determine whether the resulting optional should reflect the outer or inner parser, and document and test the chosen behavior.

Written by the indexing model from the issue text.

Description

Hi,

right now I have little time, so I write this short report. I hope to find time in the future to extend it with a reproducer and maybe a proposed fix.

There seem to be some inconsistencies, or at least a lack of documentation, around the collapsing of nested optionals.

Given for example this parser:

constexpr auto my_parser = bp::lit(U"hallo") >> -(bp::lit(u"there") >> -(bp::lit(U"Markus") >> bp::attr(true)));

Without any collapsing, the argument type would be std::optional<std::optional<bool>>. But because of the collapsing, it is a bp::optional<bool>. But now I am missing the documentation whether the state of that optional (set or not set) reflects the success of the outer optional parser or the inner optional parser.

Parsing the string "hallo there", it seems I get an optional which is set (set by the outer optional parser). But its content is default-constructed, because the inner optional parser failed and produced an std::nullopt;

My feeling is that it would be more consistent if the state of the resulting std::optional reflected the success of the inner optional parser. Either way, the behavior should be documented and tested.

Dominant language
C++
Stars
182
Forks
28
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/parser

All issues in boostorg/parser

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.