Consider the following code:

struct bar
{ virtual int get_val() { return 1; } };

int inline get_value(bar* b) { return b->get_val(); }

int main(void)
{ 
  bar b; 
  //return (&b)->get_val();    #1
  return get_value(&b);           #2
}

Using #1, the compiler optimises away all the code with -O. With #2, when
get_value is inlined into main, the optimiser seems to 'forget' it actually
knows exactly the type of b and performs an unnecessary virtual function call.

Chris


-- 
           Summary: Optimisation of virtual functions confused by inlining.
           Product: gcc
           Version: 4.2.2
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: chris at bubblescope dot net


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34217

Reply via email to