public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/115471] New: Fail to capture (with initializer) constant bit-fields by reference in lambda expression
@ 2024-06-13  7:46 fchelnokov at gmail dot com
  2024-06-13  7:55 ` [Bug c++/115471] " pinskia at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: fchelnokov at gmail dot com @ 2024-06-13  7:46 UTC (permalink / raw)
  To: gcc-bugs

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug c++/115471] Fail to capture (with initializer) constant bit-fields by reference in lambda expression
  2024-06-13  7:46 [Bug c++/115471] New: Fail to capture (with initializer) constant bit-fields by reference in lambda expression fchelnokov at gmail dot com
@ 2024-06-13  7:55 ` pinskia at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-06-13  7:55 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115471

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=90789,
                   |                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=87638

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note I don't think this has anything to do with bitfields, GCC fails even
without bitfields. See PR 90789, PR 87638 and others .

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-06-13  7:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-13  7:46 [Bug c++/115471] New: Fail to capture (with initializer) constant bit-fields by reference in lambda expression fchelnokov at gmail dot com
2024-06-13  7:55 ` [Bug c++/115471] " pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).