<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/70464>70464</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang-tidy misdiagnosing uninitialized members at the end of a constructor.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-tidy
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
cbuchner1
</td>
</tr>
</table>
<pre>
`
#include <memory>
#include <vector>
#include <cassert>
template <class T> struct foo { T x; };
class bar : public foo<double> {
public:
bar(double x) : foo{x} { }
std::shared_ptr<std::vector<char>> y;
};
int main(int argc, char **argv)
{
bar test = {12.34};
assert(test.x == 12.34);
assert(!test.y);
return 0;
}
`
I used clang-tidy based on Debian LLVM version 15.0.7 for my testing.
To reproduce the bug, execute clang-tidy repro.cpp
Here is a short reproducer for clang-tidy misdiagnosing an uninitialized member in a constructor
[clang-analyzer-optin.cplusplus.UninitializedObject]
as well as diagnosing a garbage value in test.x
[clang-analyzer-core.UndefinedBinaryOperatorResult]
even though the assert verifies that the member is being initialized correctly in the constructor.
To verify result correctness, execute clang++ -g -o repro repro.cpp && ./repro which does *not* hit the assert.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx0VE2PozgQ_TWVSykIbPJ14JB0d7QrzWqkVc9eV8augFfGRrbJJPPrVwa6w8x0H-Ig6r169fGwCEE3lqiCzQk2zysxxNb5StaDbC35YlU7da9gm0P-DPkRGNdWmkERAn_qqHP-Dvzlo-CVZHT-k6AUIZCPj-h4Rup6I-KEMCIEfAX-giH6QUa8OIewO-Er3oCfEHbPwE9L-kSphUfgR-yH2miZWMCflBtqQykZ7GbODAA-sxMR2H5C4g3YYUyT-LvTDXbPo3hSneCIIarE5sfQCk_q3z564E_vb98G8CRbMc6Bv-D9UfJv5WsbsRPaAtunR-EbCewJExuBHYEdhW-uwA5vCU7vlaSeI4WIwMcyC5bxcqmAiPPE2T4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