Handle constructor default arguments with early DMI
Fixes an issue with default member initialization in C++ constructors when using early parsing.
This commit addresses a bug in C++ parsing related to default member initialization within constructors. Previously, the parser incorrectly handled cases involving default member initializers for class-type members when performing early parsing. The fix modifies the parser to correctly check for MAYBE_CLASS_TYPE_P instead of an empty initializer list, ensuring proper handling of these constructs. A new test case validates the correction.
In Details
The C++ front-end's parser.cc handles various language constructs. This change targets an issue (PR126606, related to PR126481) where the parser's early parsing logic for non-static data members initialized with defaults (NSD MIs) failed when the member was of a class type. The fix in cp_parser_early_parsing_nsdmi changes the condition from checking for an empty initializer ({}) to checking if the member type is a class type (MAYBE_CLASS_TYPE_P). This ensures that the parser correctly defers certain semantic checks until later, as required by the C++ standard for class-type member…
- DMI
- Default Member Initialization. In C++, this refers to initializing a non-static data member of a class with a default value directly within the class definition.
- early parsing
- A compiler optimization technique where certain syntactic or semantic checks are performed earlier in the parsing process than strictly required by the language standard. This can help detect errors sooner or facilitate other optimizations.
- class type
- In C++, a type that is defined using the
classorstructkeywords. Objects of class type can have data members, member functions, and constructors. - MAYBE_CLASS_TYPE_P
- A predicate or macro used within the GCC C++ front-end to determine if a given type is potentially a class type. This is often used in parsing logic to handle constructs that apply differently to class types versus other types.