[llvm-bugs] [Bug 31709] New: compiler warning padding lambda
via llvm-bugs
llvm-bugs at lists.llvm.org
Fri Jan 20 10:25:43 PST 2017
https://llvm.org/bugs/show_bug.cgi?id=31709
Bug ID: 31709
Summary: compiler warning padding lambda
Product: clang
Version: unspecified
Hardware: Macintosh
OS: MacOS X
Status: NEW
Severity: normal
Priority: P
Component: C++11
Assignee: unassignedclangbugs at nondot.org
Reporter: nivek.research at gmail.com
CC: dgregor at apple.com, llvm-bugs at lists.llvm.org
Classification: Unclassified
The clang compiler may warn that lambda's are padded
# clang++ -std=c++11 -stdlib=libc++ -Weverything -Wno-c++98-compat main.cpp
main.cpp:22:13: warning: padding class '(lambda at main.cpp:20:45)' with 4
bytes to align anonymous bit-field [-Wpadded]
document->prepare();
^
1 warning generated.
I believe one no control over how the compiler stores the state for the lambda
so I believe the warning should not be shown.
#include <cstdint>
#include <functional>
class Document {
public:
bool unlock(void) { return true; }
void prepare(void) {}
void perform(void) {}
};
uint32_t GetCurrentEventKeyModifiers(void);
void UnlockDocumentAndCallFunction(Document* const inDocument,
std::function<void(void)> const inFunction);
int main() {
Document* const document = new Document();
uint32_t const modifiers = GetCurrentEventKeyModifiers();
UnlockDocumentAndCallFunction(document, [=]() {
if (modifiers & 1) {
document->prepare();
}
document->perform();
});
delete document;
return 0;
}
uint32_t GetCurrentEventKeyModifiers(void) {
return 1;
}
void UnlockDocumentAndCallFunction(Document* const inDocument,
std::function<void(void)> const inFunction) {
if (inDocument->unlock()) {
inFunction();
}
}
--
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/20170120/243da01c/attachment.html>
More information about the llvm-bugs
mailing list