I'm using GNU Global with a C++ project in Emacs and want to find the definition of a class member starting from any use of that member within a member function.
Example for illustration:
class Foo // Foo.h
{
int doSomething();
int bar;
};
int Foo::doSomething() // Foo.cpp
{
return bar;
}
class Foo1 // Foo1.h
{
int bar(int b);
};
int Foo1::bar(int b)
{
return b+1;
}
class Foo2 // Foo2.h
{
int bar(int b);
};
int Foo2::bar(int b)
{
return b+1;
}
I have set the environment variable GTAGSFORCECPP for C++ support.
After running gtags (without any parameters), I want to see all definitions of the name "bar" by using global -d --result=grep bar
(The -d
actually doesn't make a difference). The result is
Foo1.h:6:int Foo1::bar(int b)
Foo2.h:6:int Foo2::bar(int b)
which is missing the definition of the member Foo::bar
. On the other hand, if i search for references via global -r --result=grep bar
, the outcome is
Foo.cpp:3: return bar;
Foo.h:4: int bar;
Foo1.h:3: int bar(int b);
Foo2.h:3: int bar(int b);
How must Global be configured so that int bar;
gets classified as a definition and not as a reference?
So this is kind of the theory part. In practice, I'm using Global from within Emacs and want to find the definition of bar, when hitting M-.
on return bar;
. Emacs calls global -v --result=grep --color=always --path-style=shorter --from-here=3:Foo.cpp -- bar
which outputs the same as global -d --result=grep bar
.
I have also tried different parsers (exuberant-ctags, pygments) by setting GTAGSLABEL, but that doesn't help.