[llvm-bugs] [Bug 51325] New: covariant

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Aug 3 07:23:49 PDT 2021


            Bug ID: 51325
           Summary: covariant
           Product: clang
           Version: 12.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: pirkelbauer2 at llnl.gov
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at 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

#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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210803/fd08c18f/attachment.html>

More information about the llvm-bugs mailing list