<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/63066>63066</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [clang] Wuninitialized & Wuninitialized-const-reference - warning does not see implicit casts to base class
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang:diagnostics
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          PiotrZSL
      </td>
    </tr>
</table>

<pre>
    I run into this issue in production code, here is example:
```
#include <vector>

struct Base {
    std::vector<int> value;
};

struct Parent : Base {
    Parent(Base&, int);
};


void test(Base& obj) {
    {
        Parent obj(obj, 1);
 }
}
```
https://godbolt.org/z/s1fjEohTT

There are 3 issues here:
- variable shadowing, that's being detected with -Wshadow, 
- injection of self into self (that is stupid because constructor can access `this`
- "access" to uninitialized object

Did some tests:
```
#include <vector>

struct Base {
 std::vector<int> value;
};

struct Parent : Base {    
 Parent();
    Parent(const Parent&);
    Parent(Parent&&);
 Parent(Base, int);
    Base base;
};

struct ParentRef : Base {
    ParentRef();
    ParentRef(const Base&, int);
    Base base;
};

void test() {
    Parent obj1(obj1, 1);
    // detected by clang-analyzer-core.CallAndMessage
    // warning: Passed-by-value struct argument contains uninitialized data (e.g., field: 'value')

    Parent obj2(obj2, 2);
    // not detected (clang-analyzer-core.CallAndMessage limitation to only first issue ?)

 Parent obj3(obj3.base, 3);
    // detected by -Wuninitialized
    // warning: variable 'obj' is uninitialized when used within its own initialization

    Parent obj4(obj4);
    // detected by -Wuninitialized
    // warning: variable 'obj4' is uninitialized when used within its own initialization

    Parent obj5(std::move(obj5));
 // detected by -Wuninitialized
    // warning: variable 'obj5' is uninitialized when used within its own initialization

    ParentRef obj6(obj6, 1);
    // not detected

    ParentRef obj7(obj7, 2);
 // not detected

    ParentRef obj8(obj8.base, 3);
    // not detected
}
```

https://godbolt.org/z/qfbTe3xPc

Overall looks like issue is not detected when conversion to base class happens.
For example here:
```
Parent copy(const Parent& p) { return p; }
Parent obj4(copy(obj4));
```
This being detected as -Wuninitialized-const-reference
When this:

```
ParentRef obj6(obj6, 1);
```
is not detected.

Same with this:
```
Parent obj2(obj2, 2);
```
even that copy were made from uninitialized object, is not detected by -Wuninitialized.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0V01v2zgQ_TX0ZSBDJi3ZOfiQjxpYYBdbtAEK7I0iRzZTivSSlNP01y8oKrZkx24WaIBCtULOcN7Me8MR915tDOKKFHekeJjwNmytW31WNrh_vv45qax8Wf0BrjWgTLAQtsqD8r5FUAZ2zspWBGUNCCuR0HvYokNQHvAHb3YaCbsl-QPJb0mZ9__SK2XKCN1KBMLu9yiCdYR96he7pw-uFQHuuEcgi7v0RwAAH2R0y25fze6VCYR9gj3XLRLWbyWLh-PvocfP3KEJQNjtG87TIqHLuERoGTFF9_TmiuP03FslIaAfWIOtngi9GR8xejmemfYuu-c9zIYnQjzycPZb-dyGsPMxK3RN6HpjZWV1mFq3IXT9k9C1n9VPn-z28XEY8GNXLO4QWKqp78p3qFkGe-4UrzSC33Jpn5XZxNjClgdCFx4qVGYDEgOKgBKeVdhC9i3tjRtf3SjzhIkmtgaPuk5k6n4Ruoz-Imd8aHdKQoWCtx5BWJMqZh0IboALgd4DKfPIwgP0DAilaY1QCsFCa5RRQXGtfqKMaUURhrgflARvG-yK5X87RT-Anx1tkvcDQUcEGTK3y9vhtby4b7BjvOlEA2cCiF66yKq4_k48X7C-KrkvWF8EldYSrsu6fG9YQ52eifOoxVkS4-xcjbEYnc6O1K9eQGhuNhk3XL_8RJcJ63B6z7W-NfIv9J5v8Mz8mTsTNcVizr1HmVUvWccS6HPH3aZtYkDCmsCV8SfkljzwKCGcbqYx0FqhjuwDQheJbnQRYx_AH6OkCSWNxvQCSmPDEWksxC-RglaNCryTfLBgjX6BWjkf-ruDsPVpVMeQWAqJTauefuwd2c--jRJzLdWHpkbo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