[LLVMbugs] [Bug 17234] New: Provide a way to check for RAII temporaries
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Fri Sep 13 09:57:48 PDT 2013
http://llvm.org/bugs/show_bug.cgi?id=17234
Bug ID: 17234
Summary: Provide a way to check for RAII temporaries
Product: clang
Version: trunk
Hardware: PC
OS: All
Status: NEW
Severity: enhancement
Priority: P
Component: C++
Assignee: unassignedclangbugs at nondot.org
Reporter: benny.kra at gmail.com
CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
Classification: Unclassified
Take this example of a scoped RAII lock
void mutex_lock(int);
void mutex_unlock();
struct ScopedLock {
__attribute__((warn_unused_result)) ScopedLock(int i) { mutex_lock(i); }
~ScopedLock() { mutex_unlock(); }
};
int main() {
{
ScopedLock(42);
// Does not do what you might think.
// more code ...
}
}
The lock is immediately destroyed and does nothing, which is a typo. I tried to
add a warning here with the warn_unused_result attribute but clang only returns
a poorly worded warning:
warning: attribute 'warn_unused_result' cannot be applied to functions without
return value
It would be nice to have a way to warn on constructs like this.
--
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/20130913/4fde5272/attachment.html>
More information about the llvm-bugs
mailing list