cppast icon indicating copy to clipboard operation
cppast copied to clipboard

Error parsing nested class template

Open deadlocklogic opened this issue 2 years ago • 2 comments

  • cppast version: latest
  • parser: libclang_parser
  • clang version: 15.0.7

Explanation of the error.

Input:

namespace ns {
  template<typename T1>
  struct Test1 {
    template<typename T2>
    struct Test2 {
    };
  };
}

template <typename T1, typename T2>
void test(typename ns::Test1<T1>::template Test2<T2> s)
{
}

Output:

[libclang parser] [error] test.h:16: unable to find end of function prefix

deadlocklogic avatar Apr 13 '23 09:04 deadlocklogic

I think the library by design don't expect nested templates because consider building a cpp_template_instantiation_type you need a cpp_template_ref which most of the time is build manually but in the case of nested templates I don't exactly know what should the arguments be. Maybe each indexed entity should return its own basic_cpp_entity_ref so in worst case an AST visit could eventually find the desired value.

deadlocklogic avatar Apr 19 '23 07:04 deadlocklogic

After little digging, I found the offending line: https://github.com/foonathan/cppast/blob/f00df6675d87c6983033d270728c57a55cd3db22/src/libclang/cxtokenizer.cpp#L282 The function test is a definition but clang_isCursorDefinition is returning 0. I am not sure if it is a clang bug, need further investigation.

Update:

After trying with cindex python I noticed the same bug. Interestingly, if I make the function constexpr the bug disappears and now is treated as a definition (as it should). So I don't know what to do here or if there is a workaround (maybe submit an llvm ticket?). Thanks.

deadlocklogic avatar May 21 '23 12:05 deadlocklogic