From patchwork Wed Oct 22 15:29:13 2014
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
X-Patchwork-Submitter: Marek Polacek
+The GCC 5 release series differs from previous GCC releases in
+a number of ways. Some of
+these are a result of bug fixing, and some old behaviors have been
+intentionally changed in order to support new standards, or relaxed
+in standards-conforming ways to facilitate compilation or run-time
+performance. Some of these changes are not visible to the naked eye
+and will not cause problems when updating from older versions.
+
+However, some of these changes are visible, and can cause grief to
+users porting to GCC 5. This document is an effort to identify major
+issues and provide clear solutions in a quick and easily searched
+manner. Additions and suggestions for improvement are welcome.
+ GCC defaults to While This example now gives the following diagnostic: Furthermore, there is a difference between Porting to GCC 5
+
+C language issues
+
+Default standard is now GNU11
+
+-std=gnu11
instead of -std=gnu89
.
+This brings several changes that the users should be aware of. The following
+paragraphs describe some of these changes and suggest how to deal with them.
+Different semantincs for inline functions
+-std=gnu89
employs the GNU89 inline semantics,
+-std=gnu11
uses the C99 inline semantics. The C99 inline semantics
+requires that if a function with external linkage is declared with
+inline
function specifier, it also has to be defined in the same
+translation unit. Consequently, GCC now warns if it sees a TU such as the
+following:
+
+
+ inline int foo (void);
+
+f.c:1:12: warning: inline function 'foo' declared but never defined
+ inline int foo (void);
+ ^
+
+
+extern inline
and
+inline
:
+
+
+
+In other words, ISO C99 requires that exactly one C source file has the
+callable copy of the inline function. Consider the following program:inline
: no externally visible function is generated;
+ if the function is referenced in this TU, external definition has to
+ exist in another TU;extern inline
: externally visible function is generated;
+ inline
: same as C99 extern inline
;extern inline
: same as C99 inline
.
+ inline int
+ foo (void)
+ {
+ return 42;
+ }
+
+ int
+ main (void)
+ {
+ return foo ();
+ }
+
+
+The program above will not link with the C99 inline semantics, because there
+is not an out-of-line function foo
generated. To fix this, add the
+following declaration:
+ extern inline int foo (void);
+
+
+This declaration ensures that an externally visible function be emitted.
+To enforce the GNU89 inline semantics, you can either use the
+-fgnu89-inline
command-line option, or mark a function with the
+gnu_inline
attribute.
The C99 mode enables some warnings by default. For instance, GCC warns +about missing declarations of functions:
+ +
+ int
+ foo (void)
+ {
+ return bar ();
+ }
+
+
+This example now gives the following diagnostic:
+ ++w.c:4:10: warning: implicit declaration of function 'bar' [-Wimplicit-function-declaration] + return bar (); + ^ ++ +
To suppress this warning add the proper declaration:
+ +
+ int bar (void);
+
+
+or use -Wno-implicit-function-declaration
.
Another warning that is now turned on by default is the warning about +implicit int, as in the following snippet:
+ +
+ foo (u)
+ {
+ return u;
+ }
+
+
+This example now gives the following diagnostic:
+ ++q.c:1:1: warning: return type defaults to 'int' [-Wimplicit-int] + foo (u) + ^ +q.c: In function 'foo': +q.c:1:1: warning: type of 'u' defaults to 'int' [-Wimplicit-int] ++ +
To suppress this warning just add the proper types:
+ +
+ int
+ foo (int u)
+ {
+ return u;
+ }
+
+
+or use -Wno-implicit
or -Wno-implicit-int
.
Another warning that is now turned on by default is the warning about +returning no value in function returning non-void:
+ +
+ int
+ foo (void)
+ {
+ return;
+ }
+
+
+This example now gives the following diagnostic:
+ ++q.c:4:3: warning: 'return' with no value, in function returning non-void + return; + ^ ++ +
The fix is either to specify a proper return value, or to declare the return
+value of foo
as void
.
+
+
Previously, initializing objects with static storage duration with compound +literals was only allowed in the GNU89 mode. This restriction has been lifted +and currently it is possible to do this even in C99/C11 mode. The following +snippet is an example of such initialization:
+ +
+ struct T { int i; };
+ struct S { struct T t; };
+ static struct S s = (struct S) { .t = { 42 } };
+
+
+We used to reject such code in C99/C11 mode:
+ ++q.c:3:29: error: initializer element is not constant + static struct S s = (struct S) { .t = { 42 } }; + ^ ++ +
Note that using -Wpedantic
will cause a warning be emitted:
+q.c:3:29: warning: initializer element is not constant [-Wpedantic] + static struct S s = (struct S) { .t = { 42 } }; + ^ ++ + + + + + + + +