[LLVMbugs] [Bug 12857] New: Clang should warn about misleading use of pointer-to-member call
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Wed May 16 18:01:38 PDT 2012
http://llvm.org/bugs/show_bug.cgi?id=12857
Bug #: 12857
Summary: Clang should warn about misleading use of
pointer-to-member call
Product: clang
Version: trunk
Platform: PC
OS/Version: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: C++
AssignedTo: unassignedclangbugs at nondot.org
ReportedBy: jyasskin at google.com
CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
Classification: Unclassified
We ran into code like the following:
struct Base {virtual int Foo() {return 0;}};
struct Derived : Base {virtual int Foo() {return 1;}};
int bar(Base* b) {
return (static_cast<Derived*>(b)->*(&Derived::Foo))();
}
// From here is for illustration:
#include <iostream>
struct MoreDerived : Derived { virtual int Foo() {return 2;}};
int main() {
MoreDerived d;
std::cout << bar(&d) << '\n';
}
The author of bar() intended to avoid virtual call overhead in calling
Derived::Foo. However, the syntax he used actually behaves the same as
"static_cast<Derived*>(b)->Foo()" and results in "2". The syntax he wanted was
"static_cast<Derived*>(b)->Derived::Foo()", which results in "1".
It would be nice if clang would warn about calling through a literal
pointer-to-member, with fixits suggesting the two shorter forms.
--
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