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

           Summary: Wrong vtable for template class instantiated with
                    anonymous type
           Product: clang
           Version: 2.9
          Platform: Macintosh
        OS/Version: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
        AssignedTo: [email protected]
        ReportedBy: [email protected]
                CC: [email protected], [email protected]


Created an attachment (id=6726)
 --> (http://llvm.org/bugs/attachment.cgi?id=6726)
Sample project to show problem

If in a header I declare a template class like this:

   // header.h
   #include <assert.h>
   #include <typeinfo>

   template <typename T>
   class klass
   {
       char const* tn1 () const         { return typeid(T()).name(); }
       virtual char const* tn2 () const { return typeid(T()).name(); }
   public:
       void test () const               { assert(tn1() == tn2());    }
   };

Then in two different translation units instantiate the template class with
identically named types, but from anonymous namespaces, example:

   // foo.cc
   #include "header.h"
   namespace { struct my_type_t { }; }
   void foo () { klass<my_type_t> foo_instance; foo_instance.test(); }

   // bar.cc
   #include "header.h"
   namespace { struct my_type_t { }; }
   void bar () { klass<my_type_t> bar_instance; bar_instance.test(); }

Then the two instances will share the same vtable, meaning calling tn2() on
either will return the same value, whereas calling tn1() will return different
values.

The assertion in test() will fail for one of the two instances.

To test this, save the 3 files above and add main.cc as:

   // main.cc
   void foo ();
   void bar ();

   int main (int argc, char const *argv[])
   {
      foo();
      bar();
      return 0;
   }

Then in Terminal run:

   % clang++ {foo,bar,main}.cc && ./a.out

The result I get is:

   Assertion failed: (tn1() == tn2()), function test, file ./header.h, line 10.

I also attached an archive with the four files + build.sh.

-- 
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.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to