public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/109824] New: aligned attribute lost on first usage
@ 2023-05-12  9:35 stsp at users dot sourceforge.net
  2023-05-12  9:38 ` [Bug c++/109824] " stsp at users dot sourceforge.net
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: stsp at users dot sourceforge.net @ 2023-05-12  9:35 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 109824
           Summary: aligned attribute lost on first usage
           Product: gcc
           Version: 12.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: stsp at users dot sourceforge.net
  Target Milestone: ---

Created attachment 55063
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55063&action=edit
test case

struct a {
    short aa;
};
typedef struct a less_aligned_a __attribute__ ((aligned (1)));

static inline void foo(void)
{
#ifndef BUG
    struct a aa __attribute__((unused));
#endif
}

class t1 {
    less_aligned_a i;
public:
    less_aligned_a &get_ref() {
        return i;
    }
} __attribute__((packed));

t1 ap;
less_aligned_a* a = &ap.get_ref();

-----

$ g++ -Wall -c a.cpp 
a.cpp: In instantiation of ‘less_aligned_a& t1<T>::get_ref() [with T = int;
less_aligned_a = a]’:
a.cpp:23:32:   required from here
a.cpp:18:16: error: cannot bind packed field ‘((t1<int>*)this)->t1<int>::i’ to
‘less_aligned_a&’ {aka ‘a&’}
   18 |         return i;



But comment out the line 9 under "ifndef BUG"
and it compiles without an error.

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

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

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-12  9:35 [Bug c++/109824] New: aligned attribute lost on first usage stsp at users dot sourceforge.net
2023-05-12  9:38 ` [Bug c++/109824] " stsp at users dot sourceforge.net
2023-05-12 20:49 ` pinskia at gcc dot gnu.org
2023-05-12 22:59 ` stsp at users dot sourceforge.net
2023-05-12 23:15 ` [Bug c++/109824] aligned attribute lost when using it on a typedef of a struct if there was not an usage of the struct beforehand pinskia at gcc dot gnu.org
2023-05-12 23:18 ` 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).