Our documentation describes -Wall as enabling "all the warnings about constructions that some users consider questionable, and that are easy to avoid (or modify to prevent the warning), even in conjunction with macros."
I believe that -Wmisleading-indentation meets these criteria, and is likely to be of benefit to users who may not read release notes; it warns for indentation that's misleading, but not for indentation that's merely bad: the former are places where a user will likely want to fix the code. The fix is usually easy and obvious: fix the misleadingly-indented code. If that isn't an option for some reason, pragmas can be used to turn off the warning for a particular fragment of code: #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wmisleading-indentation" if (flag) x = 3; y = 2; #pragma GCC diagnostic pop -Wmisleading-indentation has been tested with a variety of indentation styles (see gcc/testsuite/c-c++-common/Wmisleading-indentation.c) and on a variety of real-world projects. For example, in: https://www.mail-archive.com/gcc-patches@gcc.gnu.org/msg119790.html Patrick reports: "Tested by building the linux, git, vim, sqlite and gdb-binutils sources with -Wmisleading-indentation." With the tweak earlier in this kit I believe we now have a good enough signal:noise ratio for this warning to be widely used; hence this patch adds the warning to -Wall. Bootstrapped®rtested with x86_64-pc-linux-gnu. OK for trunk? gcc/c-family/ChangeLog: * c.opt (Wmisleading-indentation): Add to -Wall for C and C++. gcc/ChangeLog: * doc/invoke.texi (-Wall): Add -Wmisleading-indentation to the list. (-Wmisleading-indentation): Update documentation to reflect being enabled by -Wall in C/C++. --- gcc/c-family/c.opt | 2 +- gcc/doc/invoke.texi | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt index e573254..d603511 100644 --- a/gcc/c-family/c.opt +++ b/gcc/c-family/c.opt @@ -562,7 +562,7 @@ C ObjC C++ ObjC++ Var(warn_memset_transposed_args) Warning LangEnabledBy(C ObjC Warn about suspicious calls to memset where the third argument is constant literal zero and the second is not. Wmisleading-indentation -C C++ Common Var(warn_misleading_indentation) Warning +C C++ Common Var(warn_misleading_indentation) Warning LangEnabledBy(C C++,Wall) Warn when the indentation of the code does not reflect the block structure. Wmissing-braces diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 5665315..abbbe5f 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -3531,6 +3531,7 @@ Options} and @ref{Objective-C and Objective-C++ Dialect Options}. -Wformat @gol -Wmain @r{(only for C/ObjC and unless} @option{-ffreestanding}@r{)} @gol -Wmaybe-uninitialized @gol +-Wmisleading-indentation @r{(only for C/C++)} @gol -Wmissing-braces @r{(only for C/ObjC)} @gol -Wnonnull @gol -Wopenmp-simd @gol @@ -3876,8 +3877,6 @@ Specifically, a warning is issued for @code{if}, @code{else}, @code{while}, and @code{for} clauses with a guarded statement that does not use braces, followed by an unguarded statement with the same indentation. -This warning is disabled by default. - In the following example, the call to ``bar'' is misleadingly indented as if it were guarded by the ``if'' conditional. @@ -3907,6 +3906,8 @@ The warning is not issued after a @code{#line} directive, since this typically indicates autogenerated code, and no assumptions can be made about the layout of the file that the directive references. +This warning is enabled by @option{-Wall} in C and C++. + @item -Wmissing-braces @opindex Wmissing-braces @opindex Wno-missing-braces -- 1.8.5.3