public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/109654] New: unnecessary "cannot bind packed field to reference" error when referenced type has aligned(1) attribute
@ 2023-04-27 20:03 richard-gccbugzilla at metafoo dot co.uk
  2023-04-27 20:14 ` [Bug c++/109654] " pinskia at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: richard-gccbugzilla at metafoo dot co.uk @ 2023-04-27 20:03 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 109654
           Summary: unnecessary "cannot bind packed field to reference"
                    error when referenced type has aligned(1) attribute
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: richard-gccbugzilla at metafoo dot co.uk
  Target Milestone: ---

As a workaround for people hitting #36566, I think GCC should accept cases like
this:


typedef __attribute__((aligned(1))) int packed_int;

struct __attribute__((packed)) Foo {
    int i;
    packed_int& get() { return i; }
};


Unfortunately GCC rejects:


<source>:5:32: error: cannot bind packed field '((Foo*)this)->Foo::i' to
'packed_int&' {aka 'int&'}
    5 |     packed_int& get() { return i; }
      |    


And conversely, GCC accepts this code, which has a genuine misalignment issue:


typedef __attribute__((aligned(1))) int packed_int;

struct __attribute__((packed)) Foo {
    packed_int i;
    int& get() { return i; }
};


I wonder if the check is mistakenly looking at the alignment of the source type
instead of the alignment of the referent of the reference type?

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

end of thread, other threads:[~2023-05-12 20:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-27 20:03 [Bug c++/109654] New: unnecessary "cannot bind packed field to reference" error when referenced type has aligned(1) attribute richard-gccbugzilla at metafoo dot co.uk
2023-04-27 20:14 ` [Bug c++/109654] " pinskia at gcc dot gnu.org
2023-04-28 21:09 ` richard-gccbugzilla at metafoo dot co.uk
2023-05-12 20:49 ` 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).