2

I've been dipping my toes in C++, and found a surprising behavior of gdb. I'm wondering if it is the expected behavior, or if I messed something up.

enum class Foo;
struct Bar { Foo a; int b; };
enum class Foo { A, B, C };

int main() {
    auto a = Foo::A;
    auto b = Bar{ Foo::A, 1 };
}

built with gcc 7.5.0 (with the -g option) and ran with gdb 8.1.1
When trying to print the value of a, or b.a, the result is <incomplete type>.
This doesn't happen if the struct declaration is not between the two enumeration declaration, or if the enumeration is fully declared once.

For the practical reason why I tried this, I had a header file containing a relatively big class declaration with some of its member being enumeration types. I felt have the full declaration of the enumerations after the class declaration was cleaner, and decided to partially declare them.

Is there something I can do to access the variable information in gdb while still doing these partial declarations, or is fully declaring my enumerations the only way.

Theses similar questions

do not concern my situation, since I have no trouble accessing the type information if the enumeration is only fully declared.

hugo
  • 33
  • 5

1 Answers1

1

Using g++ (Debian 11.2.0-10) 11.2.0 and GDB-10.0:

7           auto b = Bar{ Foo::A, 1 };
(gdb) p a
$1 = Foo::A
(gdb) n
8       }
(gdb) p b
$2 = {a = Foo::A, b = 1}

built with gcc 7.5.0 (with the -g option) and ran with gdb 8.1.1

These are pretty ancient.

Is there something I can do

I suggest trying latest released GDB (easy to build from source), and if that doesn't help, latest GCC.

Employed Russian
  • 199,314
  • 34
  • 295
  • 362