Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of C Cpp Knowledge Patch?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/nevaberry-c-cpp-knowledge-patch-nevaberry-plugins)
---
name: c-cpp-knowledge-patch
description: C and C++
version: null
license: MIT
metadata:
author: Nevaberry
---
# C and C++ Compatibility Guidance
Load this skill when migrating Clang or GCC builds, checking C or C++ language
support, updating libstdc++ or compiler tooling, or configuring diagnostics,
sanitizers, target options, and offloading.
The references contain the detailed guidance and examples. Use the topic index
to locate compiler-specific behavior and its release attribution.
## Reference index
| Reference | Topics |
| --- | --- |
| [Migration and ABI](references/migration-and-abi.md) | Dialect defaults, source migrations, mangling, calling conventions, Solaris, library ABI and random sequences |
| [Language and Standards](references/language-and-standards.md) | C and C++ modes, declarations, initialization, templates, constant evaluation, reflection, implementation gaps |
| [Code Generation and Builtins](references/codegen-and-builtins.md) | Pointer arithmetic, allocation, type queries, floating point, assembly, linking, optimized debugging |
| [Diagnostics and Safety](references/diagnostics-and-safety.md) | Warning changes, SARIF, lifetime and format annotations, thread safety, Static Analyzer, sanitizers |
| [Libraries and Tooling](references/libraries-and-tooling.md) | libstdc++, modules, compiler libraries, Python bindings, plugins, clang-format |
| [Targets and Offload](references/targets-and-offload.md) | Arm, X86, LoongArch, RISC-V, WebAssembly, Windows, CUDA/HIP, OpenCL, OpenACC, OpenMP, Swift interoperability |
## Breaking changes and deprecations
### Pin the intended C++ dialect
GCC 16.1 defaults to `-std=gnu++20`. Set `-std=gnu++17` or `-std=c++17`
explicitly to stay on C++17. Older Autoconf scripts can introduce an unintended
`-std=gnu++11` through `AC_PROG_CXX`; regenerate with Autoconf 2.73 or later
to correct the detection.
### Check pointer arithmetic before forming the pointer
Clang can fold `ptr + unsigned_offset < ptr` to false. Check the offset against
the available distance first, or use `uintptr_t` arithmetic for byte-address
wraparound. In Clang 20.1, `-fwrapv` covers signed integer overflow alone;
`-fwrapv-pointer` covers pointer overflow and `-fno-strict-overflow` enables both.
Clang 21.1 preserves legacy null-based `offsetof` idioms while optimizing null
arithmetic more aggressively; intentional null arithmetic can use
`-fwrapv-pointer` or `-fno-delete-null-pointer-checks`.
### Match ABI workarounds to the affected interface
For Clang 20.1's changed Itanium construction-vtable and member-like friend
template spellings, use `-fclang-abi-compat=19` when linking against old symbols.
For Clang 21.1's changed return convention for larger C++ records, use
`-fclang-abi-compat=20` across affected interfaces. Clang 22.1's MSVC ABI changes
require rebuilding binaries that share classes with virtual destructors;
`-fclang-abi-compat=21` restores the old behavior for `::delete`.
See the ABI reference for Arm, Solaris, layout, and libstdc++ interface changes.
### Preserve union padding when required
With GCC 15.1, outside static-storage-duration initialization, `{0}` initializes
the union's first member and can leave padding uncleared. Use `{}` where valid
or `-fzero-init-padding-bits=unions` when padding must be zero.
### Handle diagnostics that became errors
Clang 21.1 treats chained comparisons and comparison folds as errors by default.
Use `a < b && b < c` for a range test, or `-Wno-error=parentheses` to downgrade.
Clang 22.1 makes `-Wincompatible-pointer-types` an error by default;
`-Wno-error=incompatible-pointer-types` keeps it a warning during migration.
Remove redundant template heads in Clang 20.1, or downgrade the default error
with `-Wno-error=extraneous-template-head`.
### Remove obsolete template and relocation interfaces
Clang 21.1 removes `-frelaxed-template-template-args`, its negative form, and
`__is_referenceable`. Clang 22.1 removes `trivially_relocable_if_eligible`,
`replaceable_if_eligible`, and `__builtin_is_replaceable`. It retains
`__builtin_is_cpp_trivially_relocatable` and `__builtin_trivially_relocate`
with P2786 semantics and no syntax for explicitly declaring a type relocatable.
### Update libstdc++ includes and iterator adaptors
For GCC 15.1, include `<stdint.h>` for global fixed-width integer typedefs,
`<cstdint>` for their `std::` forms, and `<ostream>` for `std::endl` and `std::flush`.
Remove `<cstdbool>` and `<cstdalign>` from modern C++; replace `<ccomplex>` with
`<complex>` and `<ctgmath>` with `<cmath>` or `<complex>` as needed.
Constrain optional iterator-adaptor operations to the wrapped iterator's
capabilities: `std::vector`'s iterator-pair constructor now recognizes C++20
iterator concepts.
### Move GCC diagnostic consumers to SARIF
GCC 15.1 can add SARIF alongside text with
`gcc -fdiagnostics-add-output=sarif -c input.c`. GCC 16.1 removes
`-fdiagnostics-format=json`; switch machine-readable output and its consumers
to SARIF. The diagnostics reference also explains unused-but-set warning levels.
### Keep the intended sanitizer checks
In Clang 21.1, use `-fsanitize=undefined,vptr` to retain vptr checking alongside
the undefined-behavior group, which now excludes it. In Clang 22.1, trapping
UBSan emits detailed trap reasons in debug info by default. Optimized builds
can merge traps and lose individual reasons; disable merging for the relevant
checks with `-fno-sanitize-merge=` to preserve them.
### Migrate clang-format settings
In Clang 22.1, `AlignAfterOpenBracket` is boolean. Migrate `AlwaysBreak` and
`BlockIndent` with `BreakAfterOpenBracket*` and `BreakBeforeCloseBracket*` options.
Under `IntegerLiteralSeparator`, rename `BinaryMinDigits`, `DecimalMinDigits`,
and `HexMinDigits` to their corresponding `MinDigitsInsert` keys. See the tooling
reference for bracket variants, separator limits, and comment reflow settings.
### Update target and offload options
For Clang 22.1, replace width-suffixed AVX10 options and feature names with
unsuffixed forms, and remove `evex512` feature requests. The driver also removes
`-mevex512` and `-mno-evex512`. Use `--target=wasm32-wasip1` for WASI.
Clang 20.1's default CUDA driver enables device LTO and `-fgpu-rdc` with static
libraries, but its RDC binaries are incompatible with those produced by `nvcc`.
Select the old driver with `--no-offload-new-driver`.
## Frequently used features and support checks
### Select C modes with their implementation limits
Clang 18 first supports both `-std=c23` and inferred object declarations such
as `auto count = 3;`. Require Clang 19 or later for C23 `#embed`; Clang 19 also
adds C23 `constexpr` objects and accepts `-std=c2y`.
Clang supports type operands in `_Generic` from version 17, named loops from
version 22, and C2y initializer declarations in `if` from version 24.
Keep `static_assert` in declaration contexts with Clang: its C2y implementation
lacks the expression form. GCC 16.1 supports that form in C2Y mode.
### Initialize flexible-array counts before accessing elements
Clang's `__builtin_counted_by_ref` takes a flexible-array member expression and
returns a pointer to its `counted_by` field. Set the count before array access;
use `_Generic` in macros to handle the `void *` result for an unannotated member.
GCC 16.1 also permits `counted_by` on a pointer member, associating it with the
structure member that stores the element count.
### Express lifetime and format contracts
Apply `[[clang::lifetimebound]]` to a named parameter. Use
`[[clang::lifetime_capture_by(out)]]` when another parameter can retain a
reference to the argument. For a function that receives a format string and
supplies the arguments itself, Clang 21.1's `format_matches` checks callers
against a reference format and uses that format to check the forwarding call.
See the diagnostics reference for examples and attribute placement restrictions.
### Check module build behavior
Clang 22.1 defaults to reduced BMIs; check that two-phase builds support them
when compiling module interfaces to object files. Clang's C++20 modules support
implements only part of P1815R2: keep translation-unit-local entities out of
exported interfaces and check the importing translation unit.
With GCC 16.1's experimental C++20 modules enabled,
`g++ -std=c++20 -fmodules --compile-std-module -c main.cc` builds the
`<bits/stdc++.h>` header unit and the `std` and `std.compat` modules before
compiling `main.cc`.
### Distinguish C++ language availability by compiler
GCC 16.1 provides reflection and splicing with `-std=c++26 -freflection`.
Clang's C++2c support still lacks reflection and contracts, exceptions in
constant evaluation, the trivial-union and union lifetime changes, and the
erroneous-behavior rules for uninitialized reads. Keep explicit initialization
and lifetime management for Clang code that would rely on those changes.
Use `-std=c++2d` for Clang's draft C++29 mode; the language reference records
the missing support for defaulted postfix operators and for declaring both
`return_value` and `return_void` on one coroutine promise type.
### Use type queries and standard-library availability checks
Clang 22.1's `__builtin_dedup_pack` keeps the first occurrence of each type;
expand it with `...` in template argument lists or base specifiers in a template.
For the C++23 temporary-reference traits supported by Clang 19, check
`__cpp_lib_reference_from_temporary` in the selected standard library.
Clang 19 begins alias-template deduction while `__cpp_deduction_guides` still
reports the older level; use a compile probe for the alias form you need.
### Debug optimized code with the appropriate controls
With debug info enabled, Clang 20.1's `-fextend-variable-liveness=this` helps
keep `this` visible; use `-fextend-variable-liveness=all` or the bare flag for
all user variables. Clang 21.1's `-Og` automatically extends variable liveness.
Its `-gkey-instructions` enables steadier DWARF stepping with a supporting
debugger and implies `-g`, as does `-gno-key-instructions`. In Clang 22.1,
`-gkey-instructions` defaults on for optimized plain C or C++ emitting DWARF.
### Preserve the intended floating-point behavior
In Clang 20.1, use `-ffp-model=aggressive` for the old `-ffp-model=fast` behavior.
The revised `fast` allows infinities and NaNs and uses promoted complex division
where possible. Selecting `-fveclib=ArmPL` or `-fveclib=SLEEF` also enables
`-fno-math-errno`.
### Check library support and embedded resources
Clang's C++23 status lists the `constexpr` math changes and explicit lifetime
management as unsupported; check the selected library and compiler before
relying on constant evaluation in `<cmath>` or `std::start_lifetime_as`.
For Clang dependency scans, use `-MG` to defer missing-file errors from `#embed`.
When a C++2d embedded resource needs a starting offset, prepare a sliced build
input: Clang lacks the standard `offset` parameter.