Viladoman / StructLayout

Visual Studio Extension for C++ struct memory layout visualization
MIT License
477 stars 22 forks source link

Can't seem to visualize templated structures #16

Closed AaronBallman closed 3 years ago

AaronBallman commented 3 years ago

Perhaps I'm misusing the extension, but when I have a templated structure type, the vizualizer cannot find a structure at that location (likely because it's a templated class and not an instantiation). Consider:

template <typename ...Ty>
struct T : Ty... {
  int i;
};

template <typename Ty>
struct U { int i; };

Clicking on the structure name itself and trying to visualize yields "No structure found at the given location" for both of those examples (even though the template isn't even used in the definition of U). Perhaps it would make sense to allow visualizing the structure from a declaration? e.g.,

U<int> u; // Selecting u would pick the correct instantiation
Viladoman commented 3 years ago

At the moment the parser is only searching for locations inside a struct declaration. I am not checking for the typenames at initialization point ( just for simplicity to have the extension up and running as fast as possible). Sadly, as you described, templated declarations have unknown types when declared.

I agree there is a lot of value in also picking up the type at initialization points.

The workaround for now would be to create a dummy struct with the templated instance inside. ( not great )

Viladoman commented 3 years ago

Just submitted version 0.3.4 which makes the parser also work if the position fetched is a Variable declaration.

I hope this helps in your use cases.

AaronBallman commented 3 years ago

Thank you for the quick fix, I can confirm it works well for me in my testing!