[LLVMbugs] [Bug 8355] New: clang++ generates incorrect code if multiple classes with the same name are defined in the same function

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Mon Oct 11 11:01:16 PDT 2010


http://llvm.org/bugs/show_bug.cgi?id=8355

           Summary: clang++ generates incorrect code if multiple classes
                    with the same name are defined in the same function
           Product: clang
           Version: 2.8
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: richard-llvm at metafoo.co.uk
                CC: llvmbugs at cs.uiuc.edu, dgregor at apple.com


clang++ generates incorrect code if two classes are defined with the same name
within a function. Specifically, the constructors for both classes use the
first class's vtable.

Consider the following code:

#include <iostream>

struct I
{
  virtual void F() const = 0;
};

void Go(const I &i)
{
  i.F();
}

int main()
{
  if (true)
  {
    struct C : I
    {
      void F() const { std::cout << "A" << std::endl; }
    };
    Go(C());
  }
  if (true)
  {
    struct C : I
    {
      void F() const { std::cout << "B" << std::endl; }
    };
    Go(C());
  }
}

Under g++ and other compilers, this prints:

A
B

Under clang++, it prints:

A
A

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list