4

I am working on a C/C++ parser based on clang libtooling. I use the AST generated by clang to parse the code. Recently what I observed is that for a template class or function which is not instantiated clang does not generate AST for that class or function.

Example: Code and the corresponding AST is shown below

template <typename T>
int serializeToJson(const T& value)
{
    using OutputStream = std::ostream;
    using OutputArchive = std::istream;
    int i;
    int k;
    return i + k;
}

template <class T>
class TClass
{
    T *ptr;

    TClass() { ptr = nullptr; }
};

enter image description here

Did anybody encounter such behavior? Is this the expected behavior. I want to do the static analysis of code and I don't care whether the template classes/functions are instantiated or not. Without AST I won't be able to do the correct static analysis.

Would you please help me to fix this problem. Thanks in advance.

Thanks, Hemant

Hemant
  • 767
  • 6
  • 20

0 Answers0