https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80660

            Bug ID: 80660
           Summary: Member function pointer optimization affected by
                    incompatible virtual function
           Product: gcc
           Version: 8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: drepper.fsp+rhbz at gmail dot com
  Target Milestone: ---

Consider the following code:

struct foo final {
  int a = 0;
  int b = 0;
  void set_a(int p) { a = p; }
  void set_b(int p) { b = p; }
#ifdef VIRT
  virtual int get_a() const { return a; }
#endif
};

void (foo::*set)(int);

foo fobj1;

void bar1(int a) {
  (fobj1.*set)(a);
}

When compiling with optimization and VIRT not defined the code generated for
bar1 does correctly so elide the test for a virtual function and saves code and
time at execution time.

Adding any virtual function (such as by defining VIRT) changes this.  All of
the sudden the entire member function pointer call sequence is emitted.

This is unnecessary, though, since the present virtual function is incompatible
with the member function pointer 'set'.  Therefore the generated code should be
the same, with or without get_a defined.

Reply via email to