https://bugs.llvm.org/show_bug.cgi?id=51325

            Bug ID: 51325
           Summary: covariant
           Product: clang
           Version: 12.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangb...@nondot.org
          Reporter: pirkelbau...@llnl.gov
                CC: blitzrak...@gmail.com, dgre...@apple.com,
                    erik.pilking...@gmail.com, llvm-bugs@lists.llvm.org,
                    richard-l...@metafoo.co.uk

The attached code should be rejected (Microsoft, Intel) or print "C" (gcc,
sun/Oracle, IBM), whereas the code generated by clang++ (tested with version 6
and 12) prints "B", indicating that the pointer points at the wrong subobject.

This issue is similar but not the same as #23411, which uses virtual
inheritance.

#include <cstdio>

struct A
{
  virtual ~A() {}
  virtual A* clone() = 0;
};

struct B : A
{
  B* clone() = 0;

  virtual void prnB() { printf("B"); }
};

struct C : A
{
  C* clone() = 0;

  virtual void prnC() { printf("C"); }
};

struct D : B, C
{
  D* clone() { return new D; /* rejected by Intel/MSVC; warning by IBM */ }
};


int main() {
  D  d;
  C& c = d;
  C* cloned = c.clone(); 

  cloned->prnC(); // should print "C"

  delete cloned;
  return 0;
}

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to