public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/107571] New: Missing fallthrough attribute diagnostics
@ 2022-11-08 14:49 jakub at gcc dot gnu.org
  2022-11-08 22:27 ` [Bug c++/107571] " jakub at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-11-08 14:49 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 107571
           Summary: Missing fallthrough attribute diagnostics
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jakub at gcc dot gnu.org
  Target Milestone: ---

On:

void
foo (int n)
{
  void g(), h(), i();
  switch (n)
    {
    case 1:
    case 2:
      g();
      [[fallthrough]];
    case 3: // warning on fallthrough discouraged
      do {
        [[fallthrough]]; // error: next statement is not part of the same
substatement execution
      } while (false);
    case 6:
      do {
        [[fallthrough]]; // error: next statement is not part of the same
substatement execution
      } while (n--);
    case 7:
      while (false) {
        [[fallthrough]]; // error: next statement is not part of the same
substatement execution
      }
    case 5:
      h();
    case 4: // implementation may warn on fallthrough
      i();
      [[fallthrough]]; // error
    }
}

mentioned in https://isocpp.org/files/papers/D2552R1.pdf we don't diagnose
misplaced [[fallthrough]] in 2 spots.
The original dump shows:
  switch (n)
    {
      case 1:;
      case 2:;
      <<cleanup_point <<< Unknown tree: expr_stmt
        g () >>>>>;
      <<cleanup_point <<< Unknown tree: expr_stmt
        .FALLTHROUGH () >>>>>;
      case 3:;
      <<cleanup_point <<< Unknown tree: expr_stmt
        .FALLTHROUGH () >>>>>;
      case 6:;
      <D.2778>:;
      <<cleanup_point <<< Unknown tree: expr_stmt
        .FALLTHROUGH () >>>>>;
      if (<<cleanup_point n--  != 0>>) goto <D.2778>; else goto <D.2776>;
      <D.2776>:;
      case 7:;
      goto <D.2779>;
      <<cleanup_point <<< Unknown tree: expr_stmt
        .FALLTHROUGH () >>>>>;
      <D.2779>:;
      case 5:;
      <<cleanup_point <<< Unknown tree: expr_stmt
        h () >>>>>;
      case 4:;
      <<cleanup_point <<< Unknown tree: expr_stmt
        i () >>>>>;
      <<cleanup_point <<< Unknown tree: expr_stmt
        .FALLTHROUGH () >>>>>;
    }
so the reason we don't warn in the do { ... } while (false); case is that it
disappears probably during
genericize_c_loop and the while (false) case because the genericization in that
case makes the loop body followed by artificial label.

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

end of thread, other threads:[~2023-11-17 14:55 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-08 14:49 [Bug c++/107571] New: Missing fallthrough attribute diagnostics jakub at gcc dot gnu.org
2022-11-08 22:27 ` [Bug c++/107571] " jakub at gcc dot gnu.org
2022-11-08 22:28 ` mpolacek at gcc dot gnu.org
2022-11-08 22:40 ` jakub at gcc dot gnu.org
2022-11-09  0:36 ` joseph at codesourcery dot com
2023-11-17 14:51 ` cvs-commit at gcc dot gnu.org
2023-11-17 14:55 ` jakub 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).