https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100684
Bug ID: 100684 Summary: spurious -Wnonnull with -O1 on a C++ lambda Product: gcc Version: 11.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: msebor at gcc dot gnu.org Target Milestone: --- >From James Legg in comment pr98109 comment 2: > The false positives can often be seen when converting a lambda to a function > pointer at lower optimisation levels too. For example, in g++ 11.1.1, > compiling: > int main() > { > return static_cast<int (*)(int)>([](int x){ return x; })(0); > } > > with -Og -Wall -fsanitize=undefined results in: > /tmp/a.cc: In static member function ‘static constexpr int > main()::<lambda(int)>::_FUN(int)’: > /tmp/a.cc:3:63: warning: ‘this’ pointer is null [-Wnonnull] > 3 | return static_cast<int (*)(int)>([](int x){ return x; })(0); > | ^ > /tmp/a.cc:3:42: note: in a call to non-static member function > ‘main()::<lambda(int)>’ > 3 | return static_cast<int (*)(int)>([](int x){ return x; })(0); > | ^