BaldDemian opened a new pull request, #3839:
URL: https://github.com/apache/fory/pull/3839

   ## Why?
   
   The C++ compiler generates IDL identifiers with class declarations, 
namespaces, helper APIs, and preprocessor macro contexts.
   
   A legal IDL identifier can therefore become a C++ keyword, shadow a global 
or runtime name such as `std`, `fory`, or fixed-width integer typedefs, expand 
as a Fory macro, or collide with generated accessors, union helpers, and 
registration functions.
   
   Different IDL names can also normalize to the same C++ identifier, 
namespace, or output path. Without compiler-side handling, these cases produce 
uncompilable generated code or surface later as unclear redefinition and ODR 
errors when generated headers are combined.
   
   The compiler should resolve safe cases deterministically and reject 
irreconcilable collisions early with proper prompts.
   
   ## What does this PR do?
   
   This PR **tries** handling C++ identifier escaping and name collisions 
completely.
   It roughly follows the corresponding Rust handling in 
https://github.com/apache/fory/pull/3744 and handles many other corner cases 
unique in C++ such as macros.
   
   - Adds identifier sanitization and scope-aware name allocation for IDL 
types, fields, enum values, union cases, and package segments.
     - Escapes C++ keywords and conflicting Fory object-like macro names.
     - Reserves generated helper names such as serialization methods, union 
helpers, and registration symbols.
     - Reports an error when distinct IDL names still map to the same generated 
C++ identifier.
   
   - Uses global qualification for generated C++ runtime and standard-library 
references, including metadata macro expansion paths.
   
   - Hardens C++ union generation:
     - avoids generated union member/helper name conflicts.
     - protects generated union declarations and metadata macros from same-name 
function-like macros.
     - constructs `std::variant` alternatives by index, allowing distinct IDL 
union cases to use the same C++ payload type.
   
   ## Related issues
   
   N/A.
   
   ## AI Contribution Checklist
   
   - [ ] Substantial AI assistance was used in this PR: `yes` / `no`
   - [ ] If `yes`, I included a completed [AI Contribution 
Checklist](https://github.com/apache/fory/blob/main/AI_POLICY.md#9-contributor-checklist-for-ai-assisted-prs)
 in this PR description and the required `AI Usage Disclosure`.
   - [ ] If `yes`, my PR description includes the required `ai_review` summary 
and screenshot evidence or equivalent persisted links of the final clean AI 
review results from both fresh reviewers described in `AI_POLICY.md`, the 
Fory-guided reviewer and the independent general reviewer, on the current PR 
diff or current HEAD after the latest code changes.
   
   ## Does this PR introduce any user-facing change?
   
   N/A.
   
   ## Benchmark
   
   N/A.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to