Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error parsing nested class template #166

Open
deadlocklogic opened this issue Apr 13, 2023 · 2 comments
Open

Error parsing nested class template #166

deadlocklogic opened this issue Apr 13, 2023 · 2 comments

Comments

@deadlocklogic
Copy link

  • 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
Copy link
Author

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
Copy link
Author

deadlocklogic commented May 21, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant