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
- gdb class is incomplete type until I set breakpoint in class constructor?
- How to print <incomplete type> variable in gdb
- GDB incomplete type when having C++ virtual function
do not concern my situation, since I have no trouble accessing the type information if the enumeration is only fully declared.