[LLVMbugs] [Bug 13142] New: A call to a virtual function in the base chain of a final class gets mapped to a direct call when calling the function on an upcasted pointer

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Mon Jun 18 20:22:52 PDT 2012


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

             Bug #: 13142
           Summary: A call to a virtual function in the base chain of a
                    final class gets mapped to a direct call when calling
                    the function on an upcasted pointer
           Product: clang
           Version: unspecified
          Platform: PC
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++11
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: ehsan at mozilla.com
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified


Consider the following program, compiled with clang++ test.cpp
-std=c++11 (on 3.1):

struct Base {
 virtual void f() = 0;
};

struct Middle : Base {
 virtual void x();
 virtual void f();
};

void Middle::x() {}

struct Derived /*final*/ : Middle {
};

void foo(Derived* d) {
 static_cast<Base*>(d)->f();
}

int main() {
 foo(new Derived());
}

With the final keyword commented out, I get the following error when linking:

$ clang++ test.cpp -std=c++11
Undefined symbols for architecture x86_64:
 "__ZN6Middle1fEv", referenced from:
     __ZTV6Middle in test-FX2MFc.o
     __ZTV7Derived in test-FX2MFc.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

With it not commented out, I get the following:

$ clang++ test.cpp -std=c++11
Undefined symbols for architecture x86_64:
 "__ZN4Base1fEv", referenced from:
     __Z3fooP7Derived in test-Akba5v.o
 "__ZN6Middle1fEv", referenced from:
     __ZTV6Middle in test-Akba5v.o
     __ZTV7Derived in test-Akba5v.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

This affects Mozilla's nsBindingManager class
<http://mxr.mozilla.org/mozilla-central/source/content/xbl/src/nsBindingManager.h#33>
which I tried to mark as final bacause of this callsite:
<http://mxr.mozilla.org/mozilla-central/source/content/base/src/nsNodeUtils.cpp#50>

-- 
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