How to distinguish explicitly specified method in call

Hi all,

suppose I have these classes:

struct A {
virtual void method1() {
std::cout << “A::method1()\n”;
struct B: A {
void method1() {
std::cout << “B::method1()\n”;
int main() {
A* o = new B();
o->method1(); // ←
o->A::method1(); // ← Look identical in AST dump.
return 0;

In the AST-dump this is printed as (fragment):

-CXXMemberCallExpr 0x80560210 <line:14:3, col:14> ‘void’
-MemberExpr 0x805601ec <col:3, col:6> '<bound member function type>' ->method1 0x8055e8b0 -ImplicitCastExpr 0x805601e0 col:3 ‘struct A *’
-DeclRefExpr 0x805601c8 <col:3> 'struct A *' lvalue Var 0x8055fc28 'o' 'struct A *' -CXXMemberCallExpr 0x805602a0 <line:15:3, col:17> 'void' -MemberExpr 0x8056026c <col:3, col:9> ‘’ ->method1 0x8055e8b0
-ImplicitCastExpr 0x80560258 <col:3> 'struct A *' <LValueToRValue> -DeclRefExpr 0x8056022c col:3 ‘struct A *’ lvalue Var 0x8055fc28 ‘o’ ‘struct A *’

to me both look the same, but clang is able to distinguish them when building the executable. Can you explain how this
is done, or where I have to look to get a clue?

Your help is very much appreciated.


Looks like MemberExpr carries that information around with it; you can access it via MemberExpr::hasQualifier and MemberExpr::getQualifier. :slight_smile:

Hi George,

thanks for the explanation. I was only looking at the CXXMemberCallExpr
and CallExpr that was inherited. Will try, whether
MemberExpr::hasQualifier has the info I need.