[llvm-bugs] [Bug 45624] New: clang fails to detect using an object before it is initialized
via llvm-bugs
llvm-bugs at lists.llvm.org
Mon Apr 20 20:13:34 PDT 2020
https://bugs.llvm.org/show_bug.cgi?id=45624
Bug ID: 45624
Summary: clang fails to detect using an object before it is
initialized
Product: clang
Version: unspecified
Hardware: PC
OS: Windows NT
Status: NEW
Severity: enhancement
Priority: P
Component: C++
Assignee: unassignedclangbugs at nondot.org
Reporter: brucedawson at chromium.org
CC: blitzrakete at gmail.com, dgregor at apple.com,
erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
richard-llvm at metafoo.co.uk
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.
--
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/20200421/e4e65d07/attachment.html>
More information about the llvm-bugs
mailing list