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

Index template instantiations #813

Open
tnicolson opened this issue Oct 3, 2016 · 4 comments
Open

Index template instantiations #813

tnicolson opened this issue Oct 3, 2016 · 4 comments

Comments

@tnicolson
Copy link

Hi Anders,

Thanks so much for developing rtags; it's fast becoming indispensible!

Please consider the following code:

#include <iostream>

using namespace std;

struct Thing {
    int x {0};
};

template<typename T>
void g(T& obj) {
    obj.x += 1;
}

int main() {
    auto f = [&](auto& obj) {
        obj.x += 2;
    };

    Thing thing;
    f(thing);
    g(thing);
    cout << thing.x << endl;
}

When requesting references at point on x, rtags currently doesn't find references in functions f or g. How difficult would it be to get rtags to index the template instantiations create when f and g are called?

Thanks,

Tim

@Andersbakken
Copy link
Owner

Hi Tim

Yeah. It's a bit of a sore point for rtags. I haven't put a lot of time
into trying to figure out how to extract that information from libclang but
I have a suspicion it's not actually available through the public API. I
will try to make another attempt at it however. It's really annoying that
it kinda falls apart inside template functions.

Anders

On Mon, Oct 3, 2016 at 7:04 AM, tnicolson notifications@github.com wrote:

Hi Anders,

Thanks so much for developing rtags; it's fast becoming indispensible!

Please consider the following code:

#include

using namespace std;

struct Thing {
int x {0};
};

template
void g(T& obj) {
obj.x += 1;
}

int main() {
auto f = [&](auto& obj) {
obj.x += 2;
};

Thing thing;
f(thing);
g(thing);
cout << thing.x << endl;

}

When requesting references at point on x, rtags currently doesn't find
references in functions f or g. How difficult would it be to get rtags to
index the template instantiations create when f and g are called?

Thanks,

Tim


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#813, or mute the thread
https://github.com/notifications/unsubscribe-auth/AAEdSjPVIrcJyp-nc6WHRqj1QjrAcAYuks5qwQt-gaJpZM4KMnZc
.

@tnicolson
Copy link
Author

Thanks Anders,

Would clang_getSpecializedCursorTemplate help?

Tim

@phcerdan
Copy link

phcerdan commented Jul 23, 2017

I guess this is not easy, I think libclang doesn't expose the full AST for c++, but it would be super good.

@phord
Copy link
Contributor

phord commented Nov 7, 2017

I ran into this one today, too. But in my case I don't even use the templated typename to get to the information. The fact that the struct is templated seems to induce the failure. Here's my testcase:

#include <vector>
struct foo
{
        int bar;
};

template <bool dummy>
struct temple_struct
{
        std::vector<foo> vec;
        foo foo_inst;
        void fn()
        {
                vec[0].bar = 1;      // 'bar' here is never associated with foo
                foo_inst.bar = 2;
        }
};

struct some_struct
{
        std::vector<foo> vec;
        foo foo_inst;
        void fn()
        {
                vec[0].bar = 3;
                foo_inst.bar = 4;
        }
};

Now if I try to find all uses of "foo::bar" rtags returns three hits:

$ rc -r foo.cpp:4:14
foo.cpp:15:26:	                foo_inst.bar = 2;
foo.cpp:25:24:	                vec[0].bar = 3;
foo.cpp:26:26:	                foo_inst.bar = 4;

It misses only the one in template <bool dummy>temple_struct::std::vector<foo>.

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

4 participants