C++26 introduces a fix to the long-standing fragility of the assert() macro via proposal P2264R7. The core problem: assert() is a macro that uses the C preprocessor, which only understands parentheses for grouping — not template angle brackets or brace-initialization. This causes valid-looking assertions with templates, lambdas, or initializer lists to fail to compile unless wrapped in extra parentheses. The fix redefines assert as a variadic macro using __VA_ARGS__, making all previously broken patterns work without extra parentheses. The proposal also prevents accidental misuse of the comma operator (which would create always-true assertions), while still allowing diagnostic strings via the && operator. The change is backward-compatible and does not break existing code. As of early 2026, no major compiler supports this yet.

5m read timeFrom sandordargo.com
Post cover image
Table of contents
The macro nobody treats like a macroP2264R7: Making assert less fragileWhat about diagnostic messages?But aren’t contracts coming?Compatibility and availabilityConclusionConnect deeper

Sort: