[LLVMbugs] [Bug 10126] New: Class accessed before it is constructed not warned about

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Sun Jun 12 09:51:02 PDT 2011


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: unassignedclangbugs at nondot.org
        ReportedBy: overminddl1 at gmail.com
                CC: llvmbugs at cs.uiuc.edu, dgregor at apple.com


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.



More information about the llvm-bugs mailing list