https://bugs.llvm.org/show_bug.cgi?id=46991
Bug ID: 46991
Summary: False positives in core.NullDereference on
non_odr_use_constant DeclRefExpr to non-capture
Product: clang
Version: trunk
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P
Component: Static Analyzer
Assignee: dcough...@apple.com
Reporter: aaronpuch...@alice-dsl.net
CC: dcough...@apple.com, llvm-bugs@lists.llvm.org
On the following code:
void foo(int v);
constexpr int VAL = 1;
void bar()
{
const int& val = VAL;
[]() {
foo(val);
}();
}
the static analyzer warns
<source>:7:13: warning: Dereference of undefined pointer value
[core.NullDereference]
foo(val);
^
<source>:6:5: note: Uninitialized value stored to 'val'
[]() {
^~~~~~
<source>:6:5: note: Calling 'operator()'
[]() {
^~~~~~
<source>:7:13: note: Dereference of undefined pointer value
foo(val);
^~~
I think that's wrong, val has an initializer expression. Note that the
DeclRefExpr referring to val is marked as non_odr_use_constant, and val doesn't
need to be captured. Adding an explicit capture fixes the Static Analyzer issue
but raises a regular Clang warning:
<source>:6:6: warning: lambda capture 'val' is not required to be captured for
this use [-Wunused-lambda-capture]
[val]() {
^~~
or
<source>:6:7: warning: lambda capture 'val' is not required to be captured for
this use [-Wunused-lambda-capture]
[&val]() {
~^~~
Using a capture-default expression, i.e. [=] or [&], does not fix the issue.
--
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs