bloomberg / clangmetatool

A framework for reusing code in Clang tools
https://bloomberg.github.io/clangmetatool/
Apache License 2.0
121 stars 25 forks source link

Match a type usage and its declaration #74

Closed samanpa closed 1 year ago

samanpa commented 1 year ago

When a type alias is added for a generic type (via a using statement) the include graph currently doesn't record the usage of the type alias but only of the underlying type.

Given the usage of myvec below

#include "myvec.h"

void func() {
  myvec<int> mv;
}

And the declaration of myvec in the header myvec.h

#pragma once

#include <vector>

template <typename T>
using myvec = std::vector<T>;

clangmetatool will not notice that myvec.h is used at all.

It tries to find the declaration of myvec but ends up finding the declaration of std::vector (see https://github.com/bloomberg/clangmetatool/blob/cb17e415ffbc6b98c2f307f2aaff4be5cd56af0a/src/collectors/include_graph/include_graph_util.cpp#L240-L259).

This PR fixes this by matching both the usage of type and its declaration.

Testing performed See the attached test case

Signed-off-by: Kojo Adams kadams85@bloomberg.net