CodeCompass icon indicating copy to clipboard operation
CodeCompass copied to clipboard

Proper template handling in C++

Open bruntib opened this issue 5 years ago • 2 comments

Currently templates are not handled properly:

template <typename>
struct S
{
  int member;
};

int main()
{
  S<int> s;
  int i = s.member;
}

Issues:

  • [ ] Querying info tree on member inside the definition of S shows that this variable has only 1 usage in this code.
  • [x] Clicking on member inside main() crashes the web server. (Fix: #438)

bruntib avatar Aug 16 '20 11:08 bruntib

I tried to reproduce the error with the given example with my branch standing on de4ce6f. The crash did not happen when clicking member inside main(), the info tree gave correct usage information for this occurrence of member. However, when I pulled all commits until fcf9666, the crash did happen. I assume a recent pull request might have caused this bug.

Calling info tree on member inside the declaration of S gave the same wrong result in both cases that was described before (only 1 usage).

intjftw avatar Aug 17 '20 10:08 intjftw

This is a good catch, thanks. It is interesting, however, if I print the generated ID in this function, it shows that 3 instances of member function go to the database: two of them in line 3 with different mangled names and another one in line 6. It is not too surprising, because mangled name includes a lot of context in case of variables, so it's quite unstable. I hope USR will work better and it will solve the second half of the issue.

bruntib avatar Aug 17 '20 18:08 bruntib

I have tested this on https://codecompass.net/ on a few template classes and functions in the source code of CodeCompass itself, and I could not reproduce the usage count bug, so I consider this resolved.

mcserep avatar Feb 04 '24 11:02 mcserep