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
* [Bug c++/109654] unnecessary "cannot bind packed field to reference" error when referenced type has aligned(1) attribute
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 ` 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
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-04-27 20:14 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109654
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
See Also| |https://gcc.gnu.org/bugzill
| |a/show_bug.cgi?id=36566
Resolution|--- |INVALID
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
This won't work for templates or function overloading since GCC does NOT mangle
the alignment.
This is why it was started to be rejected in the first place.
That is:
```
typedef __attribute__((aligned(1))) int packed_int;
template <class T> T load(T &a);
int load1(int *a)
{
return load<packed_int>(*a);
}
int load2(int *a)
{
return load<int>(*a);
}
```
Will both still call load<int> in both cases.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/109654] unnecessary "cannot bind packed field to reference" error when referenced type has aligned(1) attribute
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
2 siblings, 0 replies; 4+ messages in thread
From: richard-gccbugzilla at metafoo dot co.uk @ 2023-04-28 21:09 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109654
--- Comment #2 from Richard Smith <richard-gccbugzilla at metafoo dot co.uk> ---
Hm, that doesn't explain why the second example I gave is accepted. But I
suppose what's happening there is probably just that the `packed` attribute is
ignored entirely for fields with alignment 1, so this behaves the same as
```
packed_int i;
int &r = i;
```
... which indeed doesn't produce an error or even a warning, presumably for the
same reason (the alignment isn't part of the canonical type of i).
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/109654] unnecessary "cannot bind packed field to reference" error when referenced type has aligned(1) attribute
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
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-05-12 20:49 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109654
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |stsp at users dot sourceforge.net
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 109824 has been marked as a duplicate of this bug. ***
^ 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).