https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115471
Bug ID: 115471 Summary: Fail to capture (with initializer) constant bit-fields by reference in lambda expression Product: gcc Version: 14.1.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: fchelnokov at gmail dot com Target Milestone: --- This program ``` struct U { int i : 4; }; using CU = const U; auto lm = [&y = CU{5}.i]() { return y; }; ``` is accepted by Clang and MSVC, and it shall be because when initializing a const reference from a bit-field, a temporary is created (its type is the type of the bit-field), copy initialized with the value of the bit-field, and the reference is bound to that temporary. But GCC fails here with the error: cannot capture 'CU{5}.U::i' by reference Online demo: https://gcc.godbolt.org/z/qnToW4qfY Related discussion: https://stackoverflow.com/q/78611419/7325599