[Bug c/88887] New: Warn on unexpected continuation of 'return' to new line in if statement.

jgreenhalgh at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Wed Jan 16 22:04:00 GMT 2019


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

            Bug ID: 88887
           Summary: Warn on unexpected continuation of 'return' to new
                    line in if statement.
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jgreenhalgh at gcc dot gnu.org
  Target Milestone: ---

A colleague tripped up on this typo:

  void bar();
  void
  foo (int x)
  {
    if (x) return

    bar ();
  }

Their intention was to return immediately if (x) holds, but they missed the
semicolon after 'return' and because bar() is declared with a void return type
didn't hit any warnings.

In my opinion, it would be reasonable for -wmisleading-indentation to cover a
case like this. The related case:

  void
  foo2 (int x)
  {
    if (x)
      return

    bar ();
  }

Could also be warned.


More information about the Gcc-bugs mailing list