[llvm-bugs] [Bug 48482] New: [clang-analyzer] False report about virtual method during construction
via llvm-bugs
llvm-bugs at lists.llvm.org
Fri Dec 11 04:17:50 PST 2020
https://bugs.llvm.org/show_bug.cgi?id=48482
Bug ID: 48482
Summary: [clang-analyzer] False report about virtual method
during construction
Product: clang
Version: trunk
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P
Component: Static Analyzer
Assignee: dcoughlin at apple.com
Reporter: dmitry.polukhin at gmail.com
CC: dcoughlin at apple.com, llvm-bugs at lists.llvm.org
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.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20201211/cc860cf9/attachment.html>
More information about the llvm-bugs
mailing list