On 08/30/2016 08:38 AM, David Malcolm wrote:
This patch adds fix-it hints to our warning for old-style structure
member designators, showing how to modernize them to C99 form.

For example:

modernize-named-inits.c:19:5: warning: obsolete use of designated initializer 
with ‘:’ [-Wpedantic]
  foo: 1,
     ^
  .  =

In conjunction with the not-yet-in-trunk -fdiagnostics-generate-patch,
this can generate patches like this:

--- modernize-named-inits.c
+++ modernize-named-inits.c
@@ -16,7 +16,7 @@
 /* Old-style named initializers.  */

 struct foo old_style_f = {
- foo: 1,
- bar: 2,
+ .foo= 1,
+ .bar= 2,
 };

Successfully bootstrapped&regrtested on x86_64-pc-linux-gnu.

OK for trunk?

gcc/c/ChangeLog:
        * c-parser.c (c_parser_initelt): Provide fix-it hints for
        modernizing old-style structure member designator to C99 style.

gcc/testsuite/ChangeLog:
        * gcc.dg/modernize-named-inits.c: New test case.
OK.
jeff

Reply via email to