LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 12459 - False positive for call to pure virtual member function warning caused by a cast
Summary: False positive for call to pure virtual member function warning caused by a cast
Status: NEW
Alias: None
Product: clang
Classification: Unclassified
Component: -New Bugs (show other bugs)
Version: trunk
Hardware: Other Linux
: P normal
Assignee: Unassigned Clang Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-04-04 10:58 PDT by Luboš Luňák
Modified: 2012-04-04 10:58 PDT (History)
1 user (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Luboš Luňák 2012-04-04 10:58:56 PDT
$ cat a.cpp
struct A { virtual void foo() = 0; };
struct B : A { B(); virtual void foo(); };
B::B() { static_cast< A* >( this )->foo(); }
void B::foo() {}
int main() { B b; }
$ clang++ -v
clang version 3.1 (trunk 153819)
Target: x86_64-unknown-linux-gnu
Thread model: posix
$ clang++ a.cpp
a.cpp:3:10: warning: call to pure virtual member function 'foo'; overrides of 'foo' in subclasses are not available in the
      constructor of 'A'
B::B() { static_cast< A* >( this )->foo(); }
         ^
a.cpp:1:12: note: 'foo' declared here                                                                                        
struct A { virtual void foo() = 0; };
           ^
1 warning generated.                                                                                                         
$ ./a.out
[no abort, runs fine]

Stepping through or even just running this testcase shows that B::B() calls B::foo() and not A::foo(), despite the explicit cast and the warning. The false warning is not generated without the explicit cast.