Porting to GCC 4.8

The GCC 4.8 release series differs from previous GCC releases in more
than the usual list of
changes. 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 4.8. 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.

General issues

New warnings

Improvements to the GCC infrastructure allow improvements in
the ability of several existing warnings to spot problematic code. As
such, new warnings may exist for previously warning-free code when
using -Wmaybe-uninitialized.

Although these warnings will
not result in compilation failure, often -Wall is used in
conjunction with -Werror and as a result, new warnings
are turned into new errors.

As a workaround, remove -Werror until the new warnings
are fixed, or add -Wno-maybe-uninitialized.

More aggressive loop optimizations

Improvements to the GCC infrastructure allow improvements in
the ability of the optimizers to transform loops. Some loops that
invoke undefined behavior may now be turned into endless loops.

warning: argument to ‘sizeof’ in ‘void* memset(void*, int, size_t)’ call is the same expression as the destination; did you mean to dereference it? [-Wsizeof-pointer-memaccess]
memset(p1, 0, sizeof(p1)); // error
^

Although these warnings will not result in compilation failure per
se, often -Wall is used in conjunction with
-Werror and as a result, new warnings are turned into
new errors.

To fix, either re-write to use memcpy or dereference the
last argument in the offending memset call.

As a workaround, use
-Wno-sizeof-pointer-memaccess.

Pre-processor pre-includes

The GCC pre-processor may now pre-include a file that defines certain
macros for the entirety of the translation unit. This allows
fully conformant implementations of C99/C11 and other standards that
require compiler or compiler + runtime macros that describe
implementation availability.

On GNU/Linux, <stdc-predef.h> is pre-included.

This subtle change means that some more creative uses of the
pre-processor may now fail, with the following diagnostic:

/usr/include/stdc-predef.h:0: error: Syntax error near '3'

As a workaround, the stdc-predef.h pre-include can be disabled with
the use of -ffreestanding. For non C/C++ code, use the
pre-processor flag -P.

C++ language issues

New warnings for unused local typedefs

The behavior of -Wall has changed and now includes the
new warning flag -Wunused-local-typedefs. This may
result in new warnings in code that compiled cleanly with previous
versions of GCC.

Links

For questions related to the use of GCC,
please consult these web pages and the
GCC manuals. If that fails,
the gcc-help@gcc.gnu.org
mailing list might help.
Comments on these web pages and the development of GCC are welcome on our
developer list at gcc@gcc.gnu.org.
All of our lists
have public archives.

Copyright (C)
Free Software Foundation, Inc.
Verbatim copying and distribution of this entire article is
permitted in any medium, provided this notice is preserved.