Porting to GCC 12

The GCC 12 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 to support new standards, or relaxed in standards-conforming ways to facilitate compilation or run-time performance.

Some of these changes are user visible and can cause grief when porting to GCC 12. This document is an effort to identify common issues and provide solutions. Let us know if you have suggestions for improvements!

C language issues

Computed goto now requires a pointer type

In GCC 12, a computed goto requires a pointer type. An example which was accepted before:


  void f(void)
  {
    goto *10;
  }
is no longer accepted and you need to add a cast to it like:

  void f(void)
  {
    goto *(void*)10;
  }

C++ language issues

Header dependency changes

Some C++ Standard Library headers have been changed to no longer include other headers that were being used internally by the library. As such, C++ programs that used standard library components without including the right headers will no longer compile.

The following headers are used less widely in libstdc++ and may need to be included explicitly when compiled with GCC 12:

C++ Standard Library deprecations

Warnings have been added for use of C++ standard library features that are deprecated (or no longer present at all) in recent C++ standards. Where possible, the warning suggests a modern replacement for the deprecated feature.

The std::iterator base class can usually be replaced by defining the same necessary typedefs directly in your iterator class. The std::unary_function and std::binary_function base classes can often be completely removed, or the typedefs for result_type and argument types can be defined directly in your class.

Fortran language issues

Argument name for CO_REDUCE

GCC 12 now uses OPERATION as the name of the function to the CO_REDUCE intrinsic for the pairwise reduction, thus conforming to the Fortran 2018 standard. Previous versions used OPERATOR, which conformed to TS 18508.