-
Notifications
You must be signed in to change notification settings - Fork 4.1k
add private_optional support (and wire up tests/CI)
#3278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
private_optional support (and wire up tests/CI)private_optional support (and wire up tests/CI)
| @@ -0,0 +1,132 @@ | |||
| // Minimal parser support for compiler unit tests. | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is a number of new files lacking the ASF license header
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, added the ASF license header.
cf288f6 to
922f4c4
Compare
Jens-G
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would love to also see a second opinion from the c++ Thrift committers.
| @@ -0,0 +1,35 @@ | |||
| class TestStruct : public virtual ::apache::thrift::TBase { | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure how we do that but is there a way to add the ASF file header anyway at these?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, added ASF file header to these test data files as well.
Add a new `cpp:private_optional` generator option for C++ that emits optional fields as private members and provides const getters, enabling stricter encapsulation while preserving access for generated helpers.
To keep the feature stable and exercised in automation, add fixture-based compiler tests and the minimal build/CI wiring required for those tests to build and run in the workflow (including MSVC).
### Example generated code (behavior change only, from `TestStruct`)
#### Default (no `cpp:private_optional`): optional fields stay public
```cpp
public:
int32_t required_field;
int32_t optional_field;
std::string optional_string;
```
With cpp:private_optional: optional fields become private + const getters
```cpp
public:
int32_t required_field;
const int32_t& __get_optional_field() const { return optional_field; }
const std::string& __get_optional_string() const { return optional_string; }
private:
int32_t optional_field;
std::string optional_string;
friend void swap(TestStruct &a, TestStruct &b) noexcept;
friend std::ostream& operator<<(std::ostream& out, const TestStruct& obj);
```
922f4c4 to
091a00b
Compare
Hi Jens, wondering if you have a specific set of folks in mind that needed to be mentioned in the PR? |
Add a new
cpp:private_optionalgenerator option for C++ that emits optional fields as private members and provides const getters, enabling stricter encapsulation while preserving access for generated helpers.To keep the feature stable and exercised in automation, add fixture-based compiler tests and the minimal build/CI wiring required for those tests to build and run in the workflow (including MSVC).
Example generated code (behavior change only, from
TestStruct)Default (no
cpp:private_optional): optional fields stay publicWith cpp:private_optional: optional fields become private + const getters
[skip ci]anywhere in the commit message to free up build resources.