Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

Missing -Wuninitialized warning for construction of member with another member using a constructor #19375

Open Quuxplusone opened 10 years ago

Quuxplusone commented 10 years ago
Bugzilla Link PR19376
Status NEW
Importance P normal
Reported by Argyrios Kyrtzidis (akyrtzi@gmail.com)
Reported on 2014-04-08 20:07:18 -0700
Last modified on 2014-04-08 22:38:58 -0700
Version unspecified
Hardware PC All
CC dblaikie@gmail.com, llvm-bugs@lists.llvm.org, rtrieu@google.com
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
This test case:
-------------
struct Bar {
    int val = 0;
};

struct Foo {
    Foo(const Bar& b) : val(b.val)
    {
    }

    int val;
};

class MyClass1 {
public:
    MyClass1();
private:
    Bar x;
    Bar y;
};

MyClass1::MyClass1() : x(y)
{
}

class MyClass2 {
public:
    MyClass2();
private:
    Foo x;
    Bar y;
};

MyClass2::MyClass2() : x(y)
{
}
-----------------

Only gives only warning:
test.cpp:21:26: warning: field 'y' is uninitialized when used here
      [-Wuninitialized]
MyClass1::MyClass1() : x(y)
                         ^
1 warning generated.

It should warn on MyClass2 as well.
Quuxplusone commented 10 years ago

Also tracked by rdar://16544901

Quuxplusone commented 10 years ago

false positives may be difficult to deal with - there are benign cases where two members want to be constructed with references to each other but they don't do anything with those references until later (where later happens to be "after both objects are actually constructed")

but, yeah, experiment and find out how often that comes up (just not sure what we'll suggest users do to rewrite their code when it does - but it might be there are more readable, less error-prone ways to write the code anyway)