You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
struct Node {
// incorrect note: Called C++ object pointer is null
explicit Node(Passkey passkey) { passkey.kernel->foo(); }
};
// enabling the following piece of code (normally in a different translation unit)
// demonstrates that the diagnostic is incorrect
#if 0
struct IrBuilder {
Node* create() {
const Passkey passkey(kernel_);
return new Node(passkey);
}
:19:38: warning: Called C++ object pointer is null [clang-analyzer-core.CallAndMessage]
explicit Node(Passkey passkey) { passkey.kernel->foo(); }
^
:19:38: note: Called C++ object pointer is null
1 warning generated.
The text was updated successfully, but these errors were encountered:
Aha, uhm, yeah, i see. The static analyzer indeed thinks that a combination of "const" and a field initializer causes the field to forever stay that way. We'll need to undo this relatively recently added shortcut.
Extended Description
// https://godbolt.org/z/1oze6v
struct IrBuilder;
struct Kernel;
class Passkey {
friend struct IrBuilder;
explicit Passkey(Kernel* kernel) : kernel(kernel) {}
public:
Kernel* const kernel = nullptr;
};
struct Kernel {
void foo() const;
};
struct Node {
// incorrect note: Called C++ object pointer is null
explicit Node(Passkey passkey) { passkey.kernel->foo(); }
};
// enabling the following piece of code (normally in a different translation unit)
// demonstrates that the diagnostic is incorrect
#if 0
struct IrBuilder {
Node* create() {
const Passkey passkey(kernel_);
return new Node(passkey);
}
};
Node* test(IrBuilder* ir_builder) {
return ir_builder->create();
}
#endif
The text was updated successfully, but these errors were encountered: