Gcc 什么是“降低vtable引用”?

Gcc 什么是“降低vtable引用”?,gcc,compiler-errors,compiler-warnings,clang,vtable,Gcc,Compiler Errors,Compiler Warnings,Clang,Vtable,Clang自身包含以下内容: 由于Clang具有范围高亮显示功能,因此它永远不需要将代码打印出来。这在G++中尤其糟糕,G++通常会发出包含较低vtable引用的错误,但在某些情况下,即使是GCC在尝试这样做时也会产生难以理解的错误消息 用谷歌搜索这个短语并没有什么帮助,后面的例子也完全不相关 有人能举个例子来说明它在说什么吗 谢谢。以下是一个示例: struct a { virtual int bar(); }; struct foo : public virtual a { }; v

Clang自身包含以下内容:

由于Clang具有范围高亮显示功能,因此它永远不需要将代码打印出来。这在G++中尤其糟糕,G++通常会发出包含较低vtable引用的错误,但在某些情况下,即使是GCC在尝试这样做时也会产生难以理解的错误消息

用谷歌搜索这个短语并没有什么帮助,后面的例子也完全不相关

有人能举个例子来说明它在说什么吗

谢谢。

以下是一个示例:

struct a {
  virtual int bar();
};

struct foo : public virtual a {
};

void test(foo *P) {
  return P->bar()+*P;
}
叮当声产生:

t.cc:9:18: error: invalid operands to binary expression ('int' and 'foo')
  return P->bar()+*P;
         ~~~~~~~~^~~
t.cc: In function ‘void test(foo*)’:
t.cc:9: error: no match for ‘operator+’ in ‘(((a*)P) + (*(long int*)(P->foo::<anonymous>.a::_vptr$a + -0x00000000000000020)))->a::bar() + * P’
t.cc:9: error: return-statement with a value, in function returning 'void'
GCC 4.2产生:

t.cc:9:18: error: invalid operands to binary expression ('int' and 'foo')
  return P->bar()+*P;
         ~~~~~~~~^~~
t.cc: In function ‘void test(foo*)’:
t.cc:9: error: no match for ‘operator+’ in ‘(((a*)P) + (*(long int*)(P->foo::<anonymous>.a::_vptr$a + -0x00000000000000020)))->a::bar() + * P’
t.cc:9: error: return-statement with a value, in function returning 'void'
。。为了使代码有效,然后让clang使用clang-cc1-ast dump t.cc转储其ast,您会得到:

...
void test(foo *P)
(CompoundStmt 0x10683cae8 <t.cc:8:19, line:10:1>
  (CXXMemberCallExpr 0x10683ca78 <line:9:3, col:10> 'int'
    (MemberExpr 0x10683ca40 <col:3, col:6> '<bound member function type>' ->bar 0x10683bef0
      (ImplicitCastExpr 0x10683cac8 <col:3> 'struct a *' <UncheckedDerivedToBase (virtual a)>
        (ImplicitCastExpr 0x10683ca28 <col:3> 'struct foo *' <LValueToRValue>
          (DeclRefExpr 0x10683ca00 <col:3> 'struct foo *' lvalue ParmVar 0x10683c8a0 'P' 'struct foo *'))))))

-克里斯

哇,我以前从没见过这个。如果你能解释我的猜测。