GCC Newspaper
JULY 29, 2026
Date
/
Architectures
Components
Topics
News & Policy
c++

c++: parse trivial DMI immediately [PR96645]

Parses simple non-static data member initializers earlier in C++ parsing.

This commit advances the parsing of simple non-static data member initializers (NSDMI) in C++ to occur earlier, without waiting until the end of the outermost class scope. This change aligns with evolving C++ standards (CWG2335) and addresses PR96645. It enables immediate parsing for trivial initializers that do not involve name lookup, simplifying the parsing process.

In Details

The cp_parser_member_declaration now calls a new function, cp_parser_early_parsing_nsdmi, to handle simple NSDMIs. This deviates from the previous behavior of deferring all NSDMI parsing until the end of the class scope. By parsing trivial NSDMIs (those without name lookup) immediately, the compiler adheres to CWG2335's direction and improves parsing efficiency for these cases, particularly when complete class scope context is not yet required.

For Context
non-static data member initializer (NSDMI)
A feature in C++ that allows data members of a class to be initialized directly within their declaration, without needing a separate constructor initialization list.
class scope
The region within a C++ class definition where its members (data and functions) are declared and accessible.
name lookup
The process by which the C++ compiler searches for the declarations of identifiers (like variable names, function names, or class names) used in the code.
CWG2335
A Core Working Group (CWG) issue for the C++ standard that discusses when complete class contexts are required for parsing certain constructs, aiming to allow more flexible parsing.
Filed Under: c++parsingcompiler-frontend