microsoft/winmd

Can't access a generic struct

Closed this issue · 1 comments

In my WinMD there is a method that returns IList<MyStruct>. This shows up as a TypeRef and I get IVector`1 and GenericTypeInstSig.gt.GenericArgCount() == 1, however GenericTypeInstSig.GenericArgs() is empty

Debugged this via TTT - it turns out my code was doing something like:

  if (method.Signature().ReturnType()) {
    const auto& type = method.Signature().ReturnType().Type();
    returnType = GetType(type);
  }
  // ...
  for (const auto& param : signature.Params()) {
    // ...
  }

The line where I get the Type() via const auto& was causing the generic params (along other temporaries on that line) to destroy at the end of the line. This can be fixed by removing the & from my code but I think this might be a bug still?

This is an aspect of C++ in general, not an issue with the library. See:

Chaining functions won't extend the lifetime of the "intermediate" returned temporaries.