LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 43042 - Uninitialized value when copying QSharedPointer with structured binding
Summary: Uninitialized value when copying QSharedPointer with structured binding
Status: CONFIRMED
Alias: None
Product: clang
Classification: Unclassified
Component: Static Analyzer (show other bugs)
Version: unspecified
Hardware: PC All
: P enhancement
Assignee: Artem Dergachev
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-08-19 01:18 PDT by Jan Niklas Hasse
Modified: 2019-08-19 14:06 PDT (History)
3 users (show)

See Also:
Fixed By Commit(s):


Attachments
clang++ -std=c++17 --analyze repro.ii (251.31 KB, text/plain)
2019-08-19 14:06 PDT, Artem Dergachev
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Niklas Hasse 2019-08-19 01:18:18 PDT
The following example code:


#include <QSharedPointer>

QPair<int, QSharedPointer<int>> foo() {
	return {42, nullptr};
}

int main() {
	auto [x, p] = foo();
	auto p2 = p;
}


produces the following warning:


QtCore.framework/Headers/qsharedpointer_impl.h:460:7: warning: 1st function call argument is an uninitialized value [clang-analyzer-core.CallAndMessage]
    { deref(d); }
      ^
test.cpp:9:12: note: Uninitialized value stored to '.second.d'
        auto p2 = p;
                  ^
test.cpp:10:1: note: Calling implicit destructor for 'QPair<int, QSharedPointer<int>>'
}
^
test.cpp:10:1: note: Calling '~QSharedPointer'
QtCore.framework/Headers/qsharedpointer_impl.h:315:25: note: Calling 'QSharedPointer::deref'
    ~QSharedPointer() { deref(); }
                        ^
QtCore.framework/Headers/qsharedpointer_impl.h:460:7: note: 1st function call argument is an uninitialized value
    { deref(d); }
      ^


Which is weird, since QSharedPointer's copy constructor initializes d. Is this a false-positive?

See related Qt bug report: https://bugreports.qt.io/browse/QTBUG-77641
Comment 1 Artem Dergachev 2019-08-19 14:06:35 PDT
Created attachment 22396 [details]
clang++ -std=c++17 --analyze repro.ii

Yeah, it's most likely false positive, looks like incomplete support for c++17 structured bindings in the static analyzer is causing that.

I attached a preprocessed reproducer for the reference. I'll take a look when i have time.