zsy056 opened a new pull request, #3288:
URL: https://github.com/apache/thrift/pull/3288

   Adds C++ 11 `enum class` generation to the C++ code generator. When 
`pure_enums=enum_class` is specified, generates strongly-typed enums with 
proper scoping and type safety.
   
   ## Code Generator Changes
   
   **Modified `t_cpp_generator.cc`:**
   - Added `gen_enum_class_` flag parsed from `pure_enums=enum_class` option
   - Modified `generate_enum()` to emit `enum class` when both 
`gen_pure_enums_` and `gen_enum_class_` are set
   - Fixed enum value scoping: use `static_cast<int>(Color::RED)` for array 
initialization
   - Fixed map operations: cast enum class to int in `find()` calls (no 
implicit conversion)
   
   **Test infrastructure:**
   - Created `t_cpp_generator_enum_class_tests.cc` with three test cases 
validating default, `pure_enums`, and `pure_enums=enum_class` behavior
   - Extracted common utilities to `t_cpp_generator_test_utils.h` (shared with 
`private_optional` tests)
   - Added expected output files: 
`expected_Color_{default,pure_enums,enum_class}.txt`
   
   **Build system:**
   - Added CMake compile-checks for generated code (both `private_optional` and 
`enum_class`)
   - Unified compile-check blocks with shared Boost detection
   - Ensures generated code compiles as part of standard test build
   
   ## Usage
   
   ```thrift
   enum Color {
     RED = 1,
     GREEN = 2,
     BLUE = 3
   }
   ```
   
   ```bash
   thrift --gen cpp:pure_enums=enum_class example.thrift
   ```
   
   Generates:
   ```cpp
   enum class Color {
     RED = 1,
     GREEN = 2,
     BLUE = 3
   };
   ```
   
   Backward compatible - existing behavior unchanged when option absent.
   
   ---
   
   - [ ] Did you create an [Apache 
Jira](https://issues.apache.org/jira/projects/THRIFT/issues/) ticket?  
([Request account here](https://selfserve.apache.org/jira-account.html), not 
required for trivial changes)
   - [ ] If a ticket exists: Does your pull request title follow the pattern 
"THRIFT-NNNN: describe my issue"?
   - [x] Did you squash your changes to a single commit?  (not required, but 
preferred)
   - [x] Did you do your best to avoid breaking changes?  If one was needed, 
did you label the Jira ticket with "Breaking-Change"?
   - [ ] If your change does not involve any code, include `[skip ci]` anywhere 
in the commit message to free up build resources.
   
   


-- 
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]

Reply via email to