public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/103502] New: -Wstrict-aliasing=3 doesn't warn on what is documented as UB
@ 2021-11-30 17:22 stsp at users dot sourceforge.net
  2021-11-30 21:20 ` [Bug c/103502] " pinskia at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: stsp at users dot sourceforge.net @ 2021-11-30 17:22 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 103502
           Summary: -Wstrict-aliasing=3 doesn't warn on what is documented
                    as UB
           Product: gcc
           Version: 11.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: stsp at users dot sourceforge.net
  Target Milestone: ---

https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html
---
Similarly, access by taking the address, casting the resulting pointer and
dereferencing the result has undefined behavior, even if the cast uses a union
type, e.g.:

int f() {
  double d = 3.0;
  return ((union a_union *) &d)->i;
}
---

Here is the test-case:
---
union a_union {
  int i;
  double d;
};

static int f() {
  double d = 3.0;
  return ((union a_union *) &d)->i;
}

int main()
{
    return f();
}
---

It only warns at -Wstrict-aliasing=2 or 1,
but doesn't on 3. 3 is documented as the
most precise option. So obviously it should
warn on what the official gcc manual declares
as an UB.

Note: I very much wish such construct to
not be UB. Because of the lack of a warning
on -Wstrict-aliasing=3 I was freely using
such construct for type-punning for years...
until now I've found it invalid in gcc manual.
If it is actually valid, please fix the docs,
not gcc! :)

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

end of thread, other threads:[~2021-12-01  1:26 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-30 17:22 [Bug c/103502] New: -Wstrict-aliasing=3 doesn't warn on what is documented as UB stsp at users dot sourceforge.net
2021-11-30 21:20 ` [Bug c/103502] " pinskia at gcc dot gnu.org
2021-11-30 21:30 ` stsp at users dot sourceforge.net
2021-11-30 21:34 ` pinskia at gcc dot gnu.org
2021-11-30 21:41 ` stsp at users dot sourceforge.net
2021-11-30 22:07 ` stsp at users dot sourceforge.net
2021-12-01  0:28 ` egallager at gcc dot gnu.org
2021-12-01  1:26 ` stsp at users dot sourceforge.net

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).