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

            Bug ID: 110851
           Summary: [contracts] Inheriting multiple base functions with
                    clashing contracts is not diagnosed
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ville.voutilainen at gmail dot com
  Target Milestone: ---

See https://wandbox.org/permlink/SICxkVAe2gVql3Ae

tl;dr:

struct Base1  {
  virtual void g(int x) [[ pre : x > 0 ]] {}
};
struct Base2  {
  virtual void g(int x) [[ pre : x <= 0 ]] {}
};

struct Derived : public Base1, public Base2 {
  virtual void g(int x) override {}
};

int main()
{
    Derived d1;
    Base1& b1 = d1;
    Base2& b2 = d1;
    b1.g(42);
    //b2.g(-42);
}

The various online compilers accept and run the code. On my machine, I get an
assembler diagnostic:
/tmp/ccYlVuY9.s: Assembler messages:
/tmp/ccYlVuY9.s:53: Error: symbol `_ZN7Derived1gEi' is already defined

which is saying that Derived::g(int)
is already defined.

The declaration of Derived::g() ought to be ill-formed, because the base
functions do not have the same list of contracts.

Reply via email to