This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

will c++0x "final keyword" trigger devirtualization?


  I noticed that gcc 4.7 implements the c++0x "final keyword" and jumped to test it.
I'm hoping that eventually the keyword will be used to trigger "devirtualization optimization"

for instance in this example I expect "geta" and "getb" to be compiled in th every same object code
struct A {
  virtual ~A(){}
  virtual int a() const final { return m_a;}
  int b() const { return m_a;}
  int geta() const;
  int getb() const;

  int m_a;
};
int A::geta() const { return a();}
int A::getb() const { return b();}

Is such an optimization foreseen?

at the moment this seems not to be the case 
 g++ -O2 -std=c++0x -c final.cpp 
pb-d-128-141-131-124:ctest innocent$ otool -t -V -X final.o
__ZNK1A4getaEv:
	movq	(%rdi),%rax
	movq	__ZNK1A4getbEv(%rax),%rax
	jmp	*%rax
	nop
	nopw	__ZNK1A4getaEv(%rax,%rax)
__ZNK1A4getbEv:
	movl	0x08(%rdi),%eax
	ret

(removing "final"  generates the very same object code)


  thanks,
          Vincenzo


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]