GCC Newspaper
OCTOBER 6, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
c++/contracts

Fix handling of `__contract_assert` extension in C++ contracts.

Ensures the GCC-specific `__contract_assert` keyword is correctly parsed and handled for contract assertions.

This commit corrects the parsing of the GCC-specific __contract_assert keyword used in C++26 contracts. Previously, the compiler incorrectly relied on string matching for contract_assert, failing to recognize the extended spelling. The fix identifies assertion statements by their parsed token rather than a raw string, ensuring both contract_assert and __contract_assert are treated as reserved identifiers.

In Details

The grok_contract function in contracts.cc previously identified assertion statements by direct string comparison with "contract_assert". This commit modifies it to identify the token type, correctly handling both the standard contract_assert and the GCC extension __contract_assert by mapping them to the RID_CONTASSERT reserved identifier code.

For Context
C++26 contracts
A proposed C++ standard feature (C++26) that allows developers to specify preconditions, postconditions, and assertions for functions, improving code correctness and reliability.
ICE
Internal Compiler Error, a fatal error that occurs within the compiler itself, preventing compilation.
token
The smallest meaningful unit of source code recognized by a compiler's parser, such as keywords, identifiers, operators, and literals.
Filed Under: c++contractsbugfixparser