https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91290
Bug ID: 91290 Summary: pragma maybe-uninitialized does not propagate to lambda Product: gcc Version: 10.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: mickg at mickg dot net Target Milestone: --- Using gcc 9.1.1 and 10.x: Seems like during inlining, pragmas are not propagated to the inlined code. Reproduction: g++ -Wall -Wextra -O2 (https://wandbox.org/permlink/UuZJvwuiuv0aXOaJ) -select and unselect optimization for reproduction. template <class F> int foo(int argc, char** argv, F&& f){ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wmaybe-uninitialized" int k; if (argv[argc-1]) k=argc; return f(k); #pragma GCC diagnostic pop } auto inner(const int& k) { return k*k; } int main(int argc, char** argv) { [[maybe_unused]] auto lambda = [](const auto& k) { return inner(k);}; //return foo(argc,argv,inner); //This does compile with -O0 and -O1 return foo(argc,argv,lambda); //This does _not_ compile with -O1, but does with -O0 }