[Bug c/92995] -Wmisleading-indentation and multiline string literals

jakub at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Dec 19 19:00:00 GMT 2019


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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dmalcolm at gcc dot gnu.org,
                   |                            |jakub at gcc dot gnu.org

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
This is because detect_intervening_unindent disables the warning in that case.
The rationale for the function is given in the comment:
/* Determine if there is an unindent/outdent between
   BODY_EXPLOC and NEXT_STMT_EXPLOC, to ensure that we don't
   issue a warning for cases like the following:

   (1) Preprocessor logic

        if (flagA)
          foo ();
          ^ BODY_EXPLOC
      #if SOME_CONDITION_THAT_DOES_NOT_HOLD
        if (flagB)
      #endif
          bar ();
          ^ NEXT_STMT_EXPLOC

   "bar ();" is visually aligned below "foo ();" and
   is (as far as the parser sees) the next token, but
   this isn't misleading to a human reader.

   (2) Empty macro with bad indentation

   In the following, the
     "if (i > 0)"
   is poorly indented, and ought to be on the same column as
      "engine_ref_debug(e, 0, -1)"
   However, it is not misleadingly indented, due to the presence
   of that macro.

      #define engine_ref_debug(X, Y, Z)

      if (locked)
        i = foo (0);
      else
        i = foo (1);
      engine_ref_debug(e, 0, -1)
        if (i > 0)
        return 1;

   Return true if such an unindent/outdent is detected.  */
and because the function wants to detect all kinds of non-indented things, it
works with the source line text rather than tokens etc., so I guess it would be
pretty hard to find out it should ignore some specific lines because there is a
multi-line string literal.
CCing author.


More information about the Gcc-bugs mailing list