On Tue, 7 Oct 2014, Marek Polacek wrote: > Hi! > > I'd like to kick off a discussion about moving the default standard > for C from gnu89 to gnu11. > > This really shouldn't be much of a surprise: the docs mention that > gnu11 is intended future default for a year now. I would presume now > is a good time to make this move: together with the new naming scheme > this should make GCC more modern (C89 really is as old as the hills). > And we're still in stage1. > > Prerequisites should be largely complete at this point: > - we have -Wc90-c99-compat option that warns about features not present > in ISO C90, but present in ISO C99, > - we have -Wc99-c11-compat option that warns about features not present > in ISO C99, but present in ISO C11, > - the testsuite has been adjusted so all the test that pass with gnu89 > default should pass with gnu11 default as well (see my recent batch > of cleanup patches). This unfortunately isn't correct for all archs, > I just don't have enough resources to test everything. But generally > the fallout from moving to gnu11 is easy to fix: just add proper decls > and return types (to fix defaulting to int), or for inline stuff use > -fgnu89-inline/gnu_inline attribute. I'd appreciate testing on other > architectures than x86_64/ppc64. > > The things I had to fix in the testsuite nicely reflect what we can expect > in the real life: mostly bunch of new warnings about missing declarations > and defaulting to int (this is probably going to be a pain with -Werror, > but I feel that people really should write proper declarations), different > inline semantics (in C99 semantics, the TU has to have the body of the inline > function etc.), new "return with no value, in function returning non-void" > warnings. Different rules for constant expressions, the fact that in C90 > non-lvalue arrays do not decay to pointers, slightly different rules for > compatible types (?) might come in game as well. > > In turn, you can use all C99 and C11 features even with -pedantic. > > Comments?
I think it makes sense to do this (and I expect C++ will follow with defaulting to -std=c++11 once the ABI stuff has settled). Of course it would be nice to look at the actual fallout in a whole-distribution rebuild... Thanks, Richard. > Regtested/bootstrapped on powerpc64-linux and x86_64-linux. > > 2014-10-07 Marek Polacek <pola...@redhat.com> > > * doc/invoke.texi: Update to reflect that GNU11 is the default > mode for C. > * c-common.h (c_language_kind): Update comment. > c-family/ > * c-opts.c (c_common_init_options): Make -std=gnu11 the default for C. > > diff --git gcc/c-family/c-common.h gcc/c-family/c-common.h > index 1e3477f..a895084 100644 > --- gcc/c-family/c-common.h > +++ gcc/c-family/c-common.h > @@ -445,7 +445,7 @@ struct GTY(()) sorted_fields_type { > > typedef enum c_language_kind > { > - clk_c = 0, /* C90, C94 or C99 */ > + clk_c = 0, /* C90, C94, C99 or C11 */ > clk_objc = 1, /* clk_c with ObjC features. */ > clk_cxx = 2, /* ANSI/ISO C++ */ > clk_objcxx = 3 /* clk_cxx with ObjC features. */ > diff --git gcc/c-family/c-opts.c gcc/c-family/c-opts.c > index 3f295d8..eb078e3 100644 > --- gcc/c-family/c-opts.c > +++ gcc/c-family/c-opts.c > @@ -250,6 +250,9 @@ c_common_init_options (unsigned int decoded_options_count, > > if (c_language == clk_c) > { > + /* The default for C is gnu11. */ > + set_std_c11 (false /* ISO */); > + > /* If preprocessing assembly language, accept any of the C-family > front end options since the driver may pass them through. */ > for (i = 1; i < decoded_options_count; i++) > diff --git gcc/doc/invoke.texi gcc/doc/invoke.texi > index 5fe7e15..fa84ed4 100644 > --- gcc/doc/invoke.texi > +++ gcc/doc/invoke.texi > @@ -1692,8 +1692,7 @@ interfaces) and L (Analyzability). The name @samp{c1x} > is deprecated. > > @item gnu90 > @itemx gnu89 > -GNU dialect of ISO C90 (including some C99 features). This > -is the default for C code. > +GNU dialect of ISO C90 (including some C99 features). > > @item gnu99 > @itemx gnu9x > @@ -1701,8 +1700,8 @@ GNU dialect of ISO C99. The name @samp{gnu9x} is > deprecated. > > @item gnu11 > @itemx gnu1x > -GNU dialect of ISO C11. This is intended to become the default in a > -future release of GCC. The name @samp{gnu1x} is deprecated. > +GNU dialect of ISO C11. This is the default for C code. > +The name @samp{gnu1x} is deprecated. > > @item c++98 > @itemx c++03 > > Marek > > -- Richard Biener <rguent...@suse.de> SUSE / SUSE Labs SUSE LINUX Products GmbH - Nuernberg - AG Nuernberg - HRB 16746 GF: Jeff Hawn, Jennifer Guild, Felix Imend"orffer