[LLVMbugs] [Bug 12966] New: typeid for pointer to member function returns incorrect value

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Sun May 27 12:50:09 PDT 2012


             Bug #: 12966
           Summary: typeid for pointer to member function returns
                    incorrect value
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: zhezherun at yandex.ru
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Here is a small test case that illustrates the bug:

#include <typeinfo>
#include <iostream>
#include <cstring>
using namespace std;

struct S {
    double g(double d) { return d; };
    double h(double d) const { return d + 1; };

template<typename F, typename T>
string get_name(F T::* f) {
    return typeid(f).name();

template<typename F1, typename T1, typename F2, typename T2>
void test(F1 T1::* f1, F2 T2::* f2) {
    string name11 = get_name(f1);
    string name21 = get_name(f2);
    string name12 = typeid(f1).name();
    string name22 = typeid(f2).name();
    if (name11 != name12) {
        cout << "Names for f1 differ: " << name11 << " != " << name12 << endl;
    if (name21 != name22) {
        cout << "Names for f2 differ: " << name21 << " != " << name22 << endl;

int main() {
    test(&S::g, &S::h);

This test case should not print anything, since name11 and name12 should be the
same, as well as name21 and name22. However, it prints

Names for f1 differ: M1SKFddE != M1SFddE

It looks like when typeid is called on f1 inside get_name(), it incorrectly
picks up the type_info for f2 instead (note the extra "K" in the mangled name).

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