1

The repro are simple and shown in the screencast below.

In essence:

  • write and compile (g++ -std=c++17 -O0 -g ...) a program (e.g. the one below) featuring an empty boost::optional, say b,
  • put a breakpoint anywhere,
  • start the program with the debugger, with the adapter vscode-cpptools, and wait for it to reach the breakpoint,
  • instantiate a watch on *b.

The program will crash with the following self-explanatory error:

debugging: /usr/include/boost/optional/optional.hpp:1271:
boost::optional<T>::reference_type boost::optional<T>::get()
[with T = int; reference_type = int&]: Assertion `this->is_initialized()' failed.

What I don't understand is that the debuggee itself is not invoking UB. Only the watch is, so why is the debuggee crashing? What "actor" is responsible for it?

Considering that the problem is fixed by one or both of

  • switching from boost::optional to std::optional
  • switching from vscode-cpptools to CodeLLDB

I'd say that the bug is either in boost::optional or vscode-cpptools; actually, since I don't think either should make assumption on the other, I'd be tempted to say that the bug is in both.


Here's the example program I used in the screencast below:

#include <boost/none.hpp>
#include <boost/optional/optional.hpp>
#include <optional>
#include <iostream>

int main()
{
    auto s = std::optional<int>{};
    auto b = boost::optional<int>{};
    if (s) {
        std::cout << *s << std::endl;
    }
    if (b) {
        std::cout << *b << std::endl;
    }
    std::cout << "done" << std::endl;
}

Here's a screencast showing my observations: asciicast


Additionally, I tried with just cli gdb, and I can reproduce the same issue too: asciicast

Enlico
  • 23,259
  • 6
  • 48
  • 102

0 Answers0