public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/110312] New: -Wcast-align=strict warning despite alignas
@ 2023-06-19 14:40 f.heckenbach@fh-soft.de
  2023-06-19 17:20 ` [Bug c++/110312] " pinskia at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: f.heckenbach@fh-soft.de @ 2023-06-19 14:40 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 110312
           Summary: -Wcast-align=strict warning despite alignas
           Product: gcc
           Version: 12.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: f.heckenbach@fh-soft.de
  Target Milestone: ---

% cat test.cpp
alignas (int) char a[sizeof (int)];
auto b = reinterpret_cast <int &> (a);
% g++ -c -Wcast-align=strict test.cpp  
test.cpp:2:10: warning: cast from 'char (*)[4]' to 'int*' increases required
alignment of target type [-Wcast-align]

I'd kind of understand the warning if I was casting &a to int* because the
alignas information might get lost when taking the address. So I tried casting
a reference, but apparently (telling from the message), gcc implements this via
a pointer cast anyway, so it doesn't help.

FWIW, I got this when I tried to replace aligned_storage_t (which is deprecated
in C++23 for reasons I don't really understand TBH) with a std::byte array as
suggested. Does this mean that I simply can't use -Wcast-align=strict then?

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

end of thread, other threads:[~2023-06-20  8:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-19 14:40 [Bug c++/110312] New: -Wcast-align=strict warning despite alignas f.heckenbach@fh-soft.de
2023-06-19 17:20 ` [Bug c++/110312] " pinskia at gcc dot gnu.org
2023-06-19 17:33 ` f.heckenbach@fh-soft.de
2023-06-20  8:10 ` rguenth 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).