This page is a "brief" summary of some of the huge number of improvements in GCC 12. You may also want to check out our Porting to GCC 12 page and the full GCC documentation.
struct S { float a; int : 0; float b; } or
struct T { float c; int : 0; } by value could differ
between C and C++. Starting with GCC 12 the C++ front-end no longer
removes those bit-fields from the internal representation and
per clarified psABI some targets have been changed, so that they
either ignore those bit-fields in the argument passing by value
decisions in both C and C++, or they always take them into account.
x86-64, ARM and AArch64 will always ignore them (so there is
a C ABI incompatibility between GCC 11 and earlier with GCC 12 or
later), PowerPC64 ELFv2 and S/390 always take them into account
(so there is a C++ ABI incompatibility, GCC 4.4 and earlier compatible
with GCC 12 or later, incompatible with GCC 4.5 through GCC 11).
RISC-V has changed the handling of these already starting with GCC 10.
As the ABI requires, MIPS takes them into account handling function
return values so there is a C++ ABI incompatibility with GCC 4.5
through 11. For function arguments on MIPS, refer to
the MIPS specific entry.
GCC 12 on the above targets will report such incompatibilities as
warnings or other diagnostics unless -Wno-psabi is used.
std::pair constructors have been deprecated.
These allowed the use of an rvalue and a literal 0 to
construct a pair containing a move-only type and a pointer.
The nullptr keyword should be used to initialize the pointer
member instead of a literal 0, as this is portable to other
C++ implementations.
--enable-libstdcxx-allocator
no longer supports the bitmap, mt, and
pool arguments. Those configurations had been broken for
some time.
omp_lib.h include file can no longer be
compiled with -std=f95 but now requires at least
-std=f2003. Alternatively, use the omp_lib module,
which still supports -std=f95 and is recommended to be used
instead in general.
cr16 target with the cr16-*-* configuration
has been obsoleted and will be removed in a future release.
hppa[12]*-*-hpux10* and hppa[12]*-*-hpux11*
configurations targeting 32-bit PA-RISC with HP-UX have been obsoleted and
will be removed in a future release.
m32c*-*-rtems* configuration has been obsoleted and will
be removed in a future release.
m32r-*-linux*, m32rle-*-linux*,
m68k*-*-openbsd* and vax-*-openbsd* configurations
has been removed.
-Ofast now implies
-fno-semantic-interposition.
-O2 which is now equivalent to the
original -O2 -ftree-vectorize -fvect-cost-model=very-cheap.
Note that default vectorizer cost model has been changed which used to behave
as -fvect-cost-model=cheap were specified.
-fsanitize=shadow-call-stack. This sanitizer currently
only works on AArch64 targets and it requires an environment in
which all code has been compiled with -ffixed-r18.
Its primary initial user is the Linux kernel.
close map
modifier and the affinity clause are now supported.
In addition Fortran gained additionally the following features which were
available in C and C++ before: declare variant is now
available, depobj, mutexinoutset and
iterator can now also be used with the depend
clause, defaultmap has been updated for OpenMP 5.0, and the
loop directive and combined directives involving the
master directive have been added.masked
and scope construct, the nothing and
error directives, and using primary with the
proc_bind clause and OMP_PROC_BIND environment
variable, the reproducible and unconstrained
modifiers to the order clause, and, for C/C++ only, the
align and allocator modifiers to the
allocate clause and the atomic extensions are
now available. The OMP_PLACE environment variable supports
the OpenMP 5.1 features. In addition the OMP_NUM_TEAMS and
OMP_TEAMS_THREAD_LIMIT environment variables and their
associated API routines are now supported as well as the memory-allocation
routines added for Fortran and extended for C/C++ in OpenMP 5.1. In
Fortran code, strictly structured blocks can be used.--param
openacc-kernels=decompose).
-Wopenacc-parallelism
to warn about potentially suboptimal choices related to OpenACC
parallelism.
-foffload-options= flag and the pre-existing but now
documented -foffload= flag.
-gnat2022 flag to indicate strict Ada
2022 compliance. The old -gnat2020 flag is now
deprecated.with Static aspect and can be used in more
contexts.-gnatX flag is
necessary to access these features as they are not considered
stable or standard.
type Matrix is array (Natural range 0 .. <>,
Natural range 0 .. <>) of Integer; is now valid.subtype
String_1 is String (1 .. <>);. Boundaries from slices
will "slide" to the correct lower bound of the subtype.Object.Operand notation. The follwing
code is now valid V.Add_Element(42);,
with V being a vector, for example.when constructs. Keywords
return, goto and raise
can now use when in addition to the existing
exit when. The following expression is therefore
now valid raise Constraint_Error with "Element is null"
when Element = null;case statement has been extended to cover
records and arrays as well as finer grained casing on scalar
types. In the future it is expected to provide more compile
time guarantees when accessing discriminated fields. Case
exhaustion is supported for pattern matching. An example would
be
type Sign is (Neg, Zero, Pos);
function Multiply (S1, S2 : Sign) return Sign is
(case (S1, S2) is
when (Neg, Neg) | (Pos, Pos) => Pos,
when (Zero, <>) | (<>, Zero) => Zero,
when (Neg, Pos) | (Pos, Neg) => Neg);
gnatfind and gnatxref, which were
already deprecated, have been removed.Pure
functions.__builtin_shufflevector compatible with
the clang language extension was added.unavailable was added.__builtin_assoc_barrier, was added.
It can be used to inhibit re-association of floating-point
expressions.__builtin_dynamic_object_size compatible with
the clang language extension was added.-Wbidi-chars
warns about potentially misleading UTF-8
bidirectional control characters. The default is
-Wbidi-chars=unpaired
(PR103026)-Warray-compare
warns about comparisons between two operands of
array type (PR97573)-Wattributes
has been extended so that it's
possible to use -Wno-attributes=ns::attr or
-Wno-attributes=ns:: to suppress warnings about unknown scoped
attributes (in C++11 and C2X). Similarly,
#pragma GCC diagnostic ignored_attributes "vendor::attr" can
be used to achieve the same effect
(PR101940)-std=c2x
and -std=gnu2x. Some of these features are also
supported as extensions when compiling for older language versions.
In addition to the features listed, some features previously
supported as extensions and now added to the C standard are enabled
by default in C2X mode and not diagnosed with -std=c2x
-Wpedantic.
#elifdef and #elifndef
preprocessing directives are now supported.printf and scanf format checking
with -Wformat
now supports the %b format
specified by C2X for binary integers, and the %B
format recommended by C2X for printf.
if consteval
(PR100974)auto(x):
decay-copy in the language
(PR103049)elifdef and elifndef
(PR102616)auto specifier
for pointers and references to arrays
(PR100975)void{}enum direct-list-initializationauto specifier
for pointers and references to arrays-fimplicit-constexpr can be used to
make inline functions implicitly constexpr
(git)-ffold-simple-inlines can be used
to fold calls to certain trivial inline functions (currently
std::move, std::forward,
std::addressof and std::as_const). In contrast
to inlining such calls, folding means that no intermediate code or debug
information will be generated for them; this minimizes the abstraction
penalty incurred for using these functions versus using the fundamental
operations from which they're defined (e.g. std::move versus
static_cast). This flag is enabled by default when
-fno-inline is not active.-Wuninitialized
warns about using uninitialized variables in
member initializer lists (PR19808)
-Wint-in-bool-context
is now disabled when instantiating
a template (git)-Wc++11-extensions, -Wc++14-extensions,
-Wc++17-extensions, -Wc++20-extensions,
and -Wc++23-extensions. They are enabled by default
and can be used to control existing pedwarns about occurrences of
new C++ constructs in code using an old C++ standard dialect.-Wmissing-requires
warns about missing requires
(git)std::is_constant_evaluated in if
warning was extended to warn in more cases
(PR100995)-Waddress
has been enhanced so that it now warns about, for
instance, comparing the address of a nonstatic member function to null
(PR102103)__cpp_lib_is_pointer_interconvertible and
__cpp_lib_is_layout_compatible to help the C++
library implement P0466,
Layout-compatibility and Pointer-interconvertibility Traits
(PR101539)constinit thread_local variables are optimized better
(PR101786)std::hardware_destructive_interference_size
was added, along with the
-Winterference-size
warning
(git)-fconstexpr-fp-except flag allows IEC559 floating point
exceptions in constant-expressions.std::vector, std::basic_string,
std::optional, and std::variant
can be used in constexpr functions.std::make_shared for arrays with default initialization,
and std::atomic<std::shared_ptr<T>>.std::optional.std::move_only_function<spanstream>std::basic_string::resize_and_overwritestd::unique_ptr
can be used in constexpr functions.<stacktrace>
(not built by default, requires linking to an extra library).<stdatomic.h>std::invoke_rconstexpr std::type_info::operator==bind(c)
and gaps in the handling for assumed-rank arrays, numerous other bugs
have been fixed, and an extensive set of new conformance test cases
has been added.
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 conforms to TS 18508.
-mabi=ieeelongdouble
option now selects the IEEE 128-bit floating point format
for REAL(KIND=16).
R16_IBM and R16_IEEE have been added to the
-fconvert option, the CONVERT specifyer of
the OPEN statement and the GFORTRAN_CONVERT_UNIT
environment variable.
LIBGCCJIT_ABI_16)
gcc_jit_lvalue_set_tls_model
for supporting thread-local variables
(LIBGCCJIT_ABI_17)
gcc_jit_lvalue_set_link_section
for setting the link section of global variables, analogous to
__attribute__((section(".section")))
(LIBGCCJIT_ABI_18)
LIBGCCJIT_ABI_19)
LIBGCCJIT_ABI_20)
gcc_jit_context_new_bitcast for reinterpreting the bits of an rvalue as a different type
(LIBGCCJIT_ABI_21)
gcc_jit_lvalue_set_register_name for setting a specific register for a variable
(LIBGCCJIT_ABI_22)
gcc_jit_context_set_bool_print_errors_to_stderr
(LIBGCCJIT_ABI_23)
LIBGCCJIT_ABI_24)
-march option: armv8.7-a, armv8.8-a, armv9-a.cortex-a510
argument to the -mcpu and -mtune options.
-mcpu and
-mtune options (GCC identifiers in parentheses).
ampere1).cortex-a710).cortex-x2).+ls64 option extension.memcpy,memmove and
memset standard functions. These instructions can be generated
when compiling with the +mopsoption extension.arm_neon.h header have been significantly reimplemented and
generate higher-performing code than previous GCC versions.-mtune=neoverse-512tvb is added to tune for Arm
Neoverse cores that have a total vector bandwidth of 512 bits. Please refer
to the documentation for more details.__int128_t/integer(kind=16)
was added.-fstack-protector-guard=tls and
-mstack-protector-guard-offset= options. This intended for use
in Linux kernel development. Please refer to the documentation for more
details.-mavx512fp16
compiler switch.
_Float16 type is supported on
x86 systems with SSE2 enabled. Without {-mavx512fp16},
all operations will be emulated in software and float
instructions.
-mharden-sls=[none|all|return|indirect-jmp].
-mindirect-branch-cs-prefix.
-mno-direct-extern-access
command-line option is specified.
-march= and -mtune= options
(GCC identifiers in parentheses).la464).loongarch64).-Wno-psabi is used.
-Wno-psabi is used.
-march flag has been added. The -misa
flag is now considered an alias of the -march flag.sm_53,
sm_70, sm_75 and sm_80 has been
added. These can be specified using the -march flag.sm_30, to fix support for sm_30 boards.-march-map flag has been added. The
-march-map value will be mapped to an valid
-march flag value. For instance,
-march-map=sm_50 maps to -march=sm_35.
This can be used to specify that generated code is to be executed on a
board with at least some specific compute capability, without having to
know the valid values for the -march flag.-mptx flag has been added to specify the PTX ISA version
for the generated code; permitted values are 3.1
(matches previous GCC versions), 6.0, 6.3,
and 7.0. If not specified, the used version is the minimal
version required for -march but at least 6.0.
mptx-3.1 multilib was added. This allows using older
drivers which do not support PTX ISA version 6.0.__PTX_SM__ predefined macro allows code to check the
PTX ISA target architecture being targeted by the compiler.__PTX_ISA_VERSION_MAJOR__
and __PTX_ISA_VERSION_MINOR__ predefined macros allows code
to check the PTX ISA version being targeted by the compiler.__builtin_get_texasr,
__builtin_get_texasru, __builtin_get_tfhar,
__builtin_get_tfiar, __builtin_set_texasr,
__builtin_set_texasru, __builtin_set_tfhar, and
__builtin_set_tfiar now behave as documented in all
supported configurations. On prior releases, the arguments and return
values of these functions were treated as unsigned long long
instead of as unsigned long, when the options -m32
-mpowerpc64 were in effect.
vec_cntlz_lsbb and
vec_cnttz_lsbb now behave as documented. On prior releases,
these built-in functions had incorrect semantics on little-endian targets.
__regio_symbol variable qualifier has been added.
It allows easier access in C programs to the __R30 and
__R31 CPU I/O registers.
-march= parsing.-mtune=thead-c906 is added to tune for T-HEAD
c906 cores.-Wanalyzer-use-of-uninitialized-value
warning, similar to
-Wuninitialized
and
-Wmaybe-uninitialized,
but based on an interprocedural path-sensitive analysis
(PR95006).
Such warnings are not disabled by the new
-ftrivial-auto-var-init
(see below), as the latter is considered a mitigation option.
-Wanalyzer-write-to-const
and
-Wanalyzer-write-to-string-literal
will now check for
__attribute__ ((access, ....))
on calls to externally-defined functions, and complain about read-only
regions pointed to by arguments marked with a write_only
or read_write attribute
(PR104793).
-fanalyzer-checker=taint
(in addition to -fanalyzer),
has gained four new taint-based warnings:
-Wanalyzer-tainted-allocation-size
for e.g. attacker-controlled malloc
and alloca,
-Wanalyzer-tainted-divisor
for detecting where an attacker can inject a divide-by-zero,
-Wanalyzer-tainted-offset
for attacker-controlled pointer offsets,
-Wanalyzer-tainted-size
for attacker-controlled values being used as a size parameter to
calls to memset or to functions marked with
__attribute__ ((access, ....)).
The existing
-Wanalyzer-tainted-array-index
has been reworded to talk about "attacker-controlled" rather than
"tainted" values, for consistency with the new warnings.
A new __attribute__ ((tainted_args)) has been
added to the C and C++ frontends, usable on functions, and on
function pointer callback fields in structs. The analyzer's taint
mode will treat all parameters and buffers pointed to by parameters
of such functions as being attacked-controlled, such as for
annotating system calls in an operating system kernel as being an
"attack surface".
__attribute__((const)):
it will treat such functions as returning the same value when given
the same inputs (PR104434),
and as having no side effects (PR104576).
realloc calls by
splitting the execution path into three possible outcomes for the
call:
NULLmalloc etc) and stack
(via alloca), though none of the analyzer warnings make
use of this yet in GCC 12.-Wuninitialized
is active. For best debugging, use of the new command-line option
-ftrivial-auto-var-init=pattern
can be used to fill variables with a repeated 0xFE pattern, which tends to
illuminate many bugs (e.g. pointers receive invalid addresses, sizes
and indices are very large). For best production results, the new
command-line option
-ftrivial-auto-var-init=zero
can be
used to fill variables with 0x00, which tends to provide
a safer state for bugs (e.g. pointers are NULL, strings
are NUL filled, and sizes and indices are 0).
-gctf enables the generation of CTF.
-gbtf
This is the list of problem reports (PRs) from GCC's bug tracking system that are known to be fixed in the 12.1 release. This list might not be complete (that is, it is possible that some PRs that have been fixed are not listed here).