$ cat 0.cpp template < typename R, typename T, R ( T::* method )() > static inline R dispatch( T& object ) { return ( object.*method )(); } struct X { virtual ~X(); virtual void f(); }; void test1( X& obj ) { void ( *f )( X& ) = dispatch< void, X, &X::f >; f( obj ); } void test2( X& obj ) { obj.f(); } g++-4.2.2-RC1 produces unoptimal code for test1: test1(X&): jmp void dispatch<void, X, &(X::f())>(X&) test2(X&): movq (%rdi), %rax movq 16(%rax), %r11 jmp *%r11 void dispatch<void, X, &(X::f())>(X&): movq (%rdi), %rax movq 16(%rax), %r11 jmp *%r11
If this has already been fixed on the trunk, then what is the issue?
Maybe the underlying issue is tree-optimization/3713, not fixed in less-than-trivial cases?
(In reply to comment #1) > If this has already been fixed on the trunk, then what is the issue? > 4.3 is not ready for production use. 4.2.2 is quite stable and this missed optimization introduces a redundant branch which is not expected in our heavy template code.
And enhancements only go for the next version and never on production code (release branches) (like any sane product release should happen, even physicial ones).
we clearly don't do enhancements for a release branch.