http://llvm.org/bugs/show_bug.cgi?id=10126
Summary: Class accessed before it is constructed not warned
about
Product: clang
Version: trunk
Platform: PC
OS/Version: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: C++
AssignedTo: [email protected]
ReportedBy: [email protected]
CC: [email protected], [email protected]
There is an article on GOTW listed on: http://www.gotw.ca/gotw/080.htm
It details a program bug that is not caught be almost every compiler. Here is
the example program:
"""
#include <string>
using namespace std;
class A
{
public:
A( const string& s ) { /* ... */ }
string f() { return "hello, world"; }
};
class B : public A
{
public:
B() : A( s = f() ) {} // The bug is on this line
private:
string s;
};
int main()
{
B b;
}
"""
The bug is in the A( s = f() ) call, it calls f() (which is in A and 'this' is
not constructed yet), and it sets s to it (which is in B and not constructed
yet since A is not yet constructed), then passes the result on to A.
clang++ currently issues no warning about the code even with -Wall on the trunk
as of r132876. As an enhancement, this kind of access should be warned about
on some level.
--
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