[LLVMbugs] [Bug 22833] New: False "undefined or garbage value returned" from C++14 lambda capture
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Fri Mar 6 21:43:57 PST 2015
http://llvm.org/bugs/show_bug.cgi?id=22833
Bug ID: 22833
Summary: False "undefined or garbage value returned" from C++14
lambda capture
Product: clang
Version: 3.5
Hardware: Macintosh
OS: MacOS X
Status: NEW
Severity: normal
Priority: P
Component: Static Analyzer
Assignee: kremenek at apple.com
Reporter: atwyman at dropbox.com
CC: llvmbugs at cs.uiuc.edu
Classification: Unclassified
Created attachment 14003
--> http://llvm.org/bugs/attachment.cgi?id=14003&action=edit
Runnable example
Giving a lambda capture parameter an explicit value (new feature in C++14)
causes the analyzer to believe that value is undefined. The simplest code
snippet which exhibits the problem:
auto f1 = [a=1] () {
return a;
};
const function<int()> f2 = f1;
/ws/art_hack/ArtCppHack/ArtCppHack/main.cpp:24:9: warning: Undefined or garbage
value returned to caller
return a;
^~~~~~~~
1 warning generated.
Creating the std::function is required to get the analyzer to analyze the
return path in a way which triggers the warning. Calling the lambda locally
instead doesn't cause the warning. Passing it to a template function which
calls it does trigger the warning. It doesn't seem to matter what the type of
the captured variable is, or what the expression assigned to it is. The
constant int above is the simplest example, but our real code is capturing a
shared_ptr, and gets the warning on the return value from its operator->.
I'd love to hear if there's a workaround for this I can use cleanly in my code,
short of using "#ifdef __clang_analyzer__" to compile out the whole body.
The code compiles and runs correctly, so it's only the analyzer which is
confused. I'm using the analyzer integrated into Xcode 6.1.1. A colleague
confirmed the same bug in Xcode 6.3b2.
--
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/20150307/17bcdb6d/attachment.html>
More information about the llvm-bugs
mailing list