On 05/04/2017 12:16 PM, David Malcolm wrote:
> As of r247522, fix-it-hints can suggest the insertion of new lines.
> 
> This patch updates -Wimplicit-fallthrough to provide suggestions
> with fix-it hints, showing the user where to insert "break;" or
> fallthrough attributes.
> 
> For example:
> 
>  test.c: In function 'set_x':
>  test.c:15:9: warning: this statement may fall through 
> [-Wimplicit-fallthrough=]
>         x = a;
>         ~~^~~
>  test.c:22:5: note: here
>       case 'b':
>       ^~~~
>  test.c:22:5: note: insert '__attribute__ ((fallthrough));' to silence this 
> warning
>  +        __attribute__ ((fallthrough));
>       case 'b':
>       ^~~~
>  test.c:22:5: note: insert 'break;' to avoid fall-through
>  +        break;
>       case 'b':
>       ^~~~
> 
> The idea is that if an IDE supports -fdiagnostics-parseable-fixits, the
> user can fix these issues by clicking on them.
> 
> It's loosely based on part of Marek's patch:
>   https://gcc.gnu.org/ml/gcc-patches/2016-08/msg01948.html
> but with extra logic for locating a suitable place to insert the
> fix-it hint, so that, if possible, it is on a line by itself before
> the "case", indented the same as the prior statement.  If that's not
> possible, no fix-it hint is emitted.
> 
> In Marek's patch he wrote:
>   /* For C++17, we'd recommend [[fallthrough]];, but we're not
>      there yet.  For C++11, recommend [[gnu::fallthrough]];.  */
> "[[fallthrough]]" appears to work, but it appears that lang_hooks.name
> doesn't expose C++17 yet, so the patch recommends [[gnu::fallthrough]
> for C++17.
> 
> 
> Successfully bootstrapped&regrtested on x86_64-pc-linux-gnu.
> 
> OK for trunk?
> 
> gcc/ChangeLog:
>       PR c/7652
>       * diagnostic.c (diagnostic_report_diagnostic): Only add fixits
>       to the edit_context if they can be auto-applied.
>       * gimplify.c (add_newline_fixit_with_indentation): New function.
>       (warn_implicit_fallthrough_r): Add suggestions on how to fix
>       -Wimplicit-fallthrough.
> 
> gcc/testsuite/ChangeLog:
>       PR c/7652
>       * g++.dg/Wimplicit-fallthrough-fixit-c++11.C: New test case.
>       * g++.dg/Wimplicit-fallthrough-fixit-c++98.C: New test case.
>       * gcc.dg/Wimplicit-fallthrough-fixit.c: New test case.
> 
> libcpp/ChangeLog:
>       PR c/7652
>       * include/line-map.h
>       (rich_location::fixits_cannot_be_auto_applied): New method.
>       (rich_location::fixits_can_be_auto_applied_p): New accessor.
>       (rich_location::m_fixits_cannot_be_auto_applied): New field.
>       * line-map.c (rich_location::rich_location): Initialize new field.
What's the state on this?  It looks like the diagnostic.c change is in,
but others are not?

Jeff

Reply via email to