<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-analyzer] False report about virtual method during construction"
   href="https://bugs.llvm.org/show_bug.cgi?id=48482">48482</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[clang-analyzer] False report about virtual method during construction
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>Static Analyzer
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>dcoughlin@apple.com
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>dmitry.polukhin@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dcoughlin@apple.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Minimal reproducer:

// clang++ --analyze -Xanalyzer -analyzer-output=text -Xanalyzer
-analyzer-checker='optin.cplusplus'

class Attribute {
public:
  virtual ~Attribute() = default;
  virtual int encode() const = 0;

 protected:
  Attribute() {}
};

class Number : public Attribute {
public:
  explicit Number()
      : Attribute() {}

  int encode() const override;

private:
  int number_;
};

void foo() {
  Number number;
  number.encode();
}

Output:
test.cpp:23:3: warning: Call to virtual method 'Number::encode' during
construction bypasses virtual dispatch
  number.encode();
  ^~~~~~~~~~~~~~~~~~~~~~
test.cpp:23:3: note: Call to virtual method 'Number::encode' during
construction bypasses virtual dispatch
  number.encode();
  ^~~~~~~~~~~~~~~~~~~~~~
1 warning generated.

To trigger this bug it is required to have uninitialised in c-tor member
`number_`. In full example the member was initialised later with member
function call before calling the virtual function. Problem exists starting from
at least clang 9 up to current trunk.</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>