<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - clang fails to detect using an object before it is initialized"
   href="https://bugs.llvm.org/show_bug.cgi?id=45624">45624</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>clang fails to detect using an object before it is initialized
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Windows NT
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>C++
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>brucedawson@chromium.org
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>The -Wuninitialized flag is supposed to detect when an object is used within
its own initialization, and it does that when the object is used in its own
constructor. However if the construction goes through a factory function then
the warning fails to fire.

In case 1 there is no warning. This example is a simplified repro of the
recreation of a Chromium bug seen in crrev.com/c/2157780

class Foo1 {
public:
  Foo1(const Foo1& r) {(void)r;}
};

Foo1 CreateFoo1(const Foo1& f);

Foo1 Foo1Factory() {
    // Using f to create f - no warning.
    Foo1 f = CreateFoo1(f);
    return f;
}

This example demonstrates how the warning is supposed to work.

class Foo2 {
public:
  Foo2(const Foo2* r) {}
};

Foo2* FooFactory() {
    // Using f to create f - warning.
    // error: variable 'f' is uninitialized when used within its own
initialization [-Werror,-Wuninitialized]
    Foo2* f = new Foo2(f);
    return f;
}


I don't think there is any valid use that CreateFoo1 can make of the reference
to f because it is not yet constructed. It cannot read from it or write from it
(doubly so because it is a const reference).

This is a missed opportunity of unknown value.

The build failures from crrev.com/c/2157780 are all, I believe, from a variant
on the Foo2 example.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>