Since the new path isn't always a superset of the old (see the test), and I want to keep old code working.
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
Hi, @EricWF or @akyrtzi, could I get this reviewed?
It's fallout from https://reviews.llvm.org/D26663, and I don't know how often there are llvm/libclang releases, but I'm afraid code using libclang might break without this patch, and I'd be really ashamed if that happened (since it'd be totally my fault :/)
Thanks in advance :)
(Also, please don't rush if I'm wrong being concerned about releases or similar, I'm fairly ignorant in that regard)
When I try just the test case (without the other changes), it doesn't fail when using r288438; so I'm not sure whether the test is actually testing the regression.
Hmm... You're right.
This happens when looking in the canonical type of a given type instead of the type itself, which is a CXType_Record... I'll find a way to test it.
Please, integrate test cases from D27384 into this patch and make sure that tests still pass.
test/Index/keep-going.cpp | ||
---|---|---|
22 ↗ | (On Diff #80092) | Why do you print canonicaltemplateargs before templateargs, shouldn't it be the other way around? Given that we first print type and only then canonicaltype it would make more sense IMO. |
test/Index/print-type.cpp | ||
107 | That's weird why does templateargs has 3 arguments, but canonicaltemplateargs only 1? |
Thanks for the comments!
Will address them ASAP and post back.
test/Index/keep-going.cpp | ||
---|---|---|
22 ↗ | (On Diff #80092) | Seemed easier to keep canonicaltemplateargs right after canonicaltypekind, but surely I can move templateargs before canonicaltype. |
test/Index/print-type.cpp | ||
107 | It's a template parameter pack: template <typename... T> struct Qux { }; |
test/Index/print-type.cpp | ||
---|---|---|
107 | Hmm, though you're right it may be better if it'd be expanded. I think it's kind of out of scope here (since it's a limitation that was before my patch), but if it's fine as a followup I'll try to address it after fixing this. |
Updated per comments, let me know if I should do anything else.
I didn't do the return MakeCXType(<ternary>, ...) thing since I think it was a bit less clear, but I can do that if needed.
Thanks!
test/Index/print-type.cpp | ||
---|---|---|
107 | I see, but it shouldn't be so difficult to add support for it. Seems like all you have to do is check if it's a template parameter pack and then use pack_size() and getPackAsArray() accordingly. Anyway if you don't want to implement it now, just add a TODO to the clang_Type_getNumTemplateArguments, that should suffice for now I think. |
Updated per comments. Not super happy with making these functions linear, but given template arguments aren't that numerous usually, it's probably acceptable.
tools/libclang/CXType.cpp | ||
---|---|---|
923 | static | |
926–927 | Maybe llvm::Optional can help here a bit? | |
942 | static | |
946 | Are you sure this can happen (one TemplateArgument::Pack can be inside another one)? If so you should definitely add a test case for it, otherwise let's drop this recursion altogether and use pack_size() instead. | |
962 | static | |
965 | Use llvm::Optional instead | |
989 | Ty -> QT |
Now without a really dumb off-by-one, hidden by the fact that we always indexed in-range and packs are only the last element.
That's weird why does templateargs has 3 arguments, but canonicaltemplateargs only 1?